jasmine

Angular 2 / 4 - How to test Directive @Input values?

笑着哭i 提交于 2020-12-29 10:13:15
问题 So I have a Directive that takes an input: @Directive({ selector: '[my-directive]' }) export class MyDirective { @Input('some-input') public someInput: string; } As you can see, the input should be a string value. Now, I want to write a test for this Directive, and I want to test if the input satisfies the string type: describe('MyDirective', () => { let fixture: ComponentFixture<DummyComponent>; let dummy: DummyComponent; let directive: DebugElement; beforeEach(async(() => { TestBed

Jasmine test for object properties

青春壹個敷衍的年華 提交于 2020-12-29 08:48:53
问题 What I'd like to do describe('my object', function() { it('has these properties', function() { expect(Object.keys(myObject)).toEqual([ 'property1', 'property2', ... ]); }); }); but of course Object.keys returns an array, which by definition is ordered...I'd prefer to have this test pass regardless of property ordering (which makes sense to me since there is no spec for object key ordering anyway...(at least up to ES5)). How can I verify my object has all the properties it is supposed to have,

Jasmine test for object properties

孤街浪徒 提交于 2020-12-29 08:48:51
问题 What I'd like to do describe('my object', function() { it('has these properties', function() { expect(Object.keys(myObject)).toEqual([ 'property1', 'property2', ... ]); }); }); but of course Object.keys returns an array, which by definition is ordered...I'd prefer to have this test pass regardless of property ordering (which makes sense to me since there is no spec for object key ordering anyway...(at least up to ES5)). How can I verify my object has all the properties it is supposed to have,

Jest: tests can't fail within setImmediate or process.nextTick callback

对着背影说爱祢 提交于 2020-12-29 06:28:59
问题 I'm trying to write a test for a React component that needs to complete an asynchronous action in its componentWillMount method. componentWillMount calls a function, passed as a prop, which returns a promise, and I mock this function in my test. This works fine, but if a test fails in a call to setImmediate or process.nextTick , the exception isn't handled by Jest and it exits prematurely. Below, you can see I even try to catch this exception, to no avail. How can I use something like

Jest: tests can't fail within setImmediate or process.nextTick callback

跟風遠走 提交于 2020-12-29 06:27:08
问题 I'm trying to write a test for a React component that needs to complete an asynchronous action in its componentWillMount method. componentWillMount calls a function, passed as a prop, which returns a promise, and I mock this function in my test. This works fine, but if a test fails in a call to setImmediate or process.nextTick , the exception isn't handled by Jest and it exits prematurely. Below, you can see I even try to catch this exception, to no avail. How can I use something like

Angular Directive ViewContainerRef Test Mock

隐身守侯 提交于 2020-12-29 06:18:12
问题 Given a directive used for Dynamic Component Loading with ViewContainerRef injected: import { Directive, ViewContainerRef } from '@angular/core'; @Directive({ selector: '[fooHost]' }) export class FooDirective { constructor(public viewContainerRef: ViewContainerRef) {} } How would you inject an instance or mock of ViewContainerRef in a unit test: import { FooDirective } from './foo.directive'; describe('FooDirective', () => { it('should create an instance', () => { const directive = new

Angular Directive ViewContainerRef Test Mock

倖福魔咒の 提交于 2020-12-29 06:16:10
问题 Given a directive used for Dynamic Component Loading with ViewContainerRef injected: import { Directive, ViewContainerRef } from '@angular/core'; @Directive({ selector: '[fooHost]' }) export class FooDirective { constructor(public viewContainerRef: ViewContainerRef) {} } How would you inject an instance or mock of ViewContainerRef in a unit test: import { FooDirective } from './foo.directive'; describe('FooDirective', () => { it('should create an instance', () => { const directive = new

How to write test cases for Subscriber and timeout inside ngOnit method?

倾然丶 夕夏残阳落幕 提交于 2020-12-27 06:18:17
问题 I have a class in angular8 application with following ngOnit method ngOnInit(): void { this.setCustomizedValues(); this.sub = PubSub.subscribe('highlightEntity', (subId, entityIdentifier: string) => { document.querySelector(entityIdentifier).classList.add('highlight'); setTimeout(() => { document.querySelector(entityIdentifier).classList.remove('highlight'); }, 2000); }); } I have initialised the following test case describe('aComponent', () => { let httpCallerServiceStub = jasmine

How to write test cases for Subscriber and timeout inside ngOnit method?

让人想犯罪 __ 提交于 2020-12-27 06:18:17
问题 I have a class in angular8 application with following ngOnit method ngOnInit(): void { this.setCustomizedValues(); this.sub = PubSub.subscribe('highlightEntity', (subId, entityIdentifier: string) => { document.querySelector(entityIdentifier).classList.add('highlight'); setTimeout(() => { document.querySelector(entityIdentifier).classList.remove('highlight'); }, 2000); }); } I have initialised the following test case describe('aComponent', () => { let httpCallerServiceStub = jasmine

How to write test cases for Subscriber and timeout inside ngOnit method?

醉酒当歌 提交于 2020-12-27 06:15:37
问题 I have a class in angular8 application with following ngOnit method ngOnInit(): void { this.setCustomizedValues(); this.sub = PubSub.subscribe('highlightEntity', (subId, entityIdentifier: string) => { document.querySelector(entityIdentifier).classList.add('highlight'); setTimeout(() => { document.querySelector(entityIdentifier).classList.remove('highlight'); }, 2000); }); } I have initialised the following test case describe('aComponent', () => { let httpCallerServiceStub = jasmine