Skip to content

Commit

Permalink
Test that bindingNames and propTypes overrides injectedProps
Browse files Browse the repository at this point in the history
  • Loading branch information
fand committed Dec 7, 2017
1 parent 8e03472 commit 893bdc5
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class TestSix extends React.Component<any> {
<p>{this.state.$http}</p>
<p>{this.state.$element}</p>
<p>{this.state.testSixService}</p>
<p>{this.props.foo}</p>
<span>$element result</span>
</div>
}
Expand All @@ -90,19 +91,32 @@ class TestSix extends React.Component<any> {
}
}

class TestSeven extends React.Component<any> {
static propTypes = {
foo: React.PropTypes.string.isRequired
}

render() {
return <p>{this.props.foo}</p>
}
}

const TestAngularOne = react2angular(TestOne, ['foo', 'bar', 'baz'])
const TestAngularTwo = react2angular(TestTwo, ['foo', 'bar', 'baz'])
const TestAngularThree = react2angular(TestThree)
const TestAngularFour = react2angular(TestFour)
const TestAngularSix = react2angular(TestSix, null, ['$http', '$element', 'testSixService'])
const TestAngularSix = react2angular(TestSix, ['foo'], ['$http', '$element', 'testSixService', 'foo'])
const TestAngularSeven = react2angular(TestSeven, null, ['foo'])

module('test', ['bcherny/ngimport'])
.component('testAngularOne', TestAngularOne)
.component('testAngularTwo', TestAngularTwo)
.component('testAngularThree', TestAngularThree)
.component('testAngularFour', TestAngularFour)
.service('testSixService', ['$q', TestSixService])
.constant('foo', 'CONSTANT FOO')
.component('testAngularSix', TestAngularSix)
.component('testAngularSeven', TestAngularSeven)

bootstrap($(), ['test'], { strictDi: true })

Expand Down Expand Up @@ -249,18 +263,28 @@ describe('react2angular', () => {
})

it('should take injected props', (done) => {
const scope = $rootScope.$new(true)
spyOn($http, 'get').and.returnValue(Promise.resolve('$http response'))
const scope = Object.assign($rootScope.$new(true), {
foo: 'FOO',
})

const element1 = $(`<test-angular-six foo="foo"></test-angular-six>`)
$compile(element1)(scope)

const element2 = $(`<test-angular-seven foo="foo"></test-angular-seven>`)
$compile(element2)(scope)

const element = $(`<test-angular-six></test-angular-six>`)
$compile(element)(scope)
$rootScope.$apply()

setTimeout(() => {
expect($http.get).toHaveBeenCalledWith('https://example.com/')
expect(element.find('p').eq(0).text()).toBe('$http response', '$http is injected')
expect(element.find('p').eq(1).text()).toBe('$element result', '$element is injected')
expect(element.find('p').eq(2).text()).toBe('testSixService result', 'testSixService is injected')
expect(element1.find('p').eq(0).text()).toBe('$http response', '$http is injected')
expect(element1.find('p').eq(1).text()).toBe('$element result', '$element is injected')
expect(element1.find('p').eq(2).text()).toBe('testSixService result', 'testSixService is injected')
expect(element1.find('p').eq(3).text()).toBe('FOO', 'bindingNames overrides injectedProps')

expect(element2.find('p').text()).toBe('FOO', 'propTypes overrides injectedProps')

done()
}, 0)
})
Expand Down

0 comments on commit 893bdc5

Please sign in to comment.