diff --git a/test.tsx b/test.tsx index 044a4eb..4f8b3ee 100644 --- a/test.tsx +++ b/test.tsx @@ -73,6 +73,7 @@ class TestSix extends React.Component {

{this.state.$http}

{this.state.$element}

{this.state.testSixService}

+

{this.props.foo}

$element result } @@ -90,11 +91,22 @@ class TestSix extends React.Component { } } +class TestSeven extends React.Component { + static propTypes = { + foo: React.PropTypes.string.isRequired + } + + render() { + return

{this.props.foo}

+ } +} + 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) @@ -102,7 +114,9 @@ module('test', ['bcherny/ngimport']) .component('testAngularThree', TestAngularThree) .component('testAngularFour', TestAngularFour) .service('testSixService', ['$q', TestSixService]) + .constant('foo', 'CONSTANT FOO') .component('testAngularSix', TestAngularSix) + .component('testAngularSeven', TestAngularSeven) bootstrap($(), ['test'], { strictDi: true }) @@ -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 = $(``) + $compile(element1)(scope) + + const element2 = $(``) + $compile(element2)(scope) - const element = $(``) - $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) })