-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
null-object.spec.ts
49 lines (44 loc) · 1.9 KB
/
null-object.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { StageComponent, ComponentTester } from 'aurelia-testing';
import { bootstrap } from 'aurelia-bootstrapper';
import { NullableObjectForm } from './resources/nullable-object-form';
import { configure, blur, change } from './shared';
describe('ValidationController', () => {
it('handles bindings with null objects', (done: () => void) => {
const component: ComponentTester = StageComponent
.withResources()
.inView('<nullable-object-form></nullable-object-form>')
.boundTo({});
component.bootstrap(configure);
let viewModel: NullableObjectForm;
const renderer = { render: jasmine.createSpy() };
component.create(bootstrap as any)
// grab some references.
.then(() => {
viewModel = component.viewModel;
viewModel.controller.addRenderer(renderer);
})
.then(() => expect(viewModel.controller.errors.length).toBe(0))
.then(() => blur(viewModel.input))
.then(() => expect(viewModel.controller.errors.length).toBe(1))
.then(() => change(viewModel.input, 'test'))
.then(() => expect(viewModel.controller.errors.length).toBe(1))
.then(() => blur(viewModel.input))
.then(() => expect(viewModel.controller.errors.length).toBe(0))
.then(() => viewModel._obj = null)
.then(() => blur(viewModel.input))
.then(() => expect(viewModel.obj).toBe(null))
.then(() => expect(viewModel.controller.errors.length).toBe(0))
.then(() => viewModel._obj = { prop: '' })
.then(() => blur(viewModel.input))
.then(() => expect(viewModel.controller.errors.length).toBe(1))
.then(() => {
viewModel._obj = null;
// wait for dirty-checking...
return new Promise(resolve => setTimeout(resolve, 500));
})
.then(() => expect(viewModel.controller.errors.length).toBe(0))
// cleanup and finish.
.then(() => component.dispose())
.then(() => done());
});
});