cnunciato / ng-mock-component

An Angular module for mocking components.
MIT License
53 stars 13 forks source link

Explanation/Support for Verifying Input Binding #6

Closed DArrigoni closed 7 years ago

DArrigoni commented 7 years ago

Is there support for verifying whether you've correctly bound the right values to a sub-component? If so, how? If not, any suggestions on how to add it?

my-component.html

<my-sub-component [foo]='bar'></my-sub-component>

my-component.html.spec.ts


...
const MockMySubComponent = MockComponent({ selector: 'my-sub-component', inputs: ['foo'] });

beforeEach(() => { TestBed.configureTestingModule({ declarations: [ MyComponent, MockMySubComponent ] }).compileComponents();

fixture = TestBed.createComponent(MyComponent);

})

describe('My Sub Component', ()=> { it('should bind bar to foo', ()=> { ?????? });

});

cnunciato commented 7 years ago

Since we're ultimately just rendering markup here, you should be able to do something like:

fixture.detectChanges();
let mocked = fixture.debugElement.query(By.css('my-sub-component')).nativeElement;
expect(mocked.nativeElement.getAttribute("[foo]")).toBe('what-you-expect');
cnunciato commented 7 years ago

Closing this for now -- if it doesn't help, or if you run into any problems, feel free to reopen. Thanks!