1
- import { customElement , LitElement } from "lit-element" ;
2
- import { expect , fixtureSync , html , waitUntil } from "@open-wc/testing" ;
3
- import sinon , { SinonStub } from "sinon" ;
1
+ import { expect , fixtureSync , html , waitUntil } from '@open-wc/testing' ;
2
+ import sinon , { SinonStub } from 'sinon' ;
4
3
5
- import { NOT_FOUND_ERROR , SERVER_ERROR } from "../../../src/compas-services/foundation.js" ;
6
- import { CompasExistsIn , CompasExistsInElement } from "../../../src/compas/CompasExistsIn.js" ;
4
+ import { customElement , LitElement } from 'lit-element' ;
5
+
6
+ import {
7
+ NOT_FOUND_ERROR ,
8
+ SERVER_ERROR ,
9
+ } from '../../../src/compas-services/foundation.js' ;
10
+
11
+ import {
12
+ CompasExistsIn ,
13
+ CompasExistsInElement ,
14
+ } from '../../../src/compas/CompasExistsIn.js' ;
7
15
8
16
@customElement ( 'mock-compas-exists-in' )
9
17
export class MockSetter extends CompasExistsIn ( LitElement ) { }
@@ -16,7 +24,8 @@ describe('CompasExistsInElement', () => {
16
24
beforeEach ( async ( ) => {
17
25
// Overwrite, because this scenario is the only on different.
18
26
element = fixtureSync (
19
- html `< mock-compas-exists-in > </ mock-compas-exists-in > ` ) ;
27
+ html `< mock-compas-exists-in > </ mock-compas-exists-in > `
28
+ ) ;
20
29
21
30
stubCallService = sinon . stub ( element , 'callService' ) . callsFake ( ( ) => {
22
31
return Promise . reject ( ) ;
@@ -35,10 +44,16 @@ describe('CompasExistsInElement', () => {
35
44
describe ( 'when service call returns a message' , ( ) => {
36
45
beforeEach ( async ( ) => {
37
46
element = fixtureSync (
38
- html `< mock-compas-exists-in docId ="some-id " docName ="some-scl.scd "> </ mock-compas-exists-in > ` ) ;
47
+ html `< mock-compas-exists-in
48
+ docId ="some-id "
49
+ docName ="some-scl.scd "
50
+ > </ mock-compas-exists-in > `
51
+ ) ;
39
52
40
53
stubCallService = sinon . stub ( element , 'callService' ) . callsFake ( ( ) => {
41
- const doc = < Document > document . implementation . createDocument ( "" , "" , null ) ;
54
+ const doc = < Document > (
55
+ document . implementation . createDocument ( '' , '' , null )
56
+ ) ;
42
57
return Promise . resolve ( doc ) ;
43
58
} ) ;
44
59
@@ -48,17 +63,21 @@ describe('CompasExistsInElement', () => {
48
63
49
64
it ( 'the document exists' , ( ) => {
50
65
expect ( element . existInCompas ) . to . be . equal ( true ) ;
51
- sinon . assert . calledOnce ( stubCallService )
66
+ sinon . assert . calledTwice ( stubCallService ) ;
52
67
} ) ;
53
68
} ) ;
54
69
55
70
describe ( 'when service call returns a not found error' , ( ) => {
56
71
beforeEach ( async ( ) => {
57
72
element = fixtureSync (
58
- html `< mock-compas-exists-in docId ="some-id " docName ="some-scl.scd "> </ mock-compas-exists-in > ` ) ;
73
+ html `< mock-compas-exists-in
74
+ docId ="some-id "
75
+ docName ="some-scl.scd "
76
+ > </ mock-compas-exists-in > `
77
+ ) ;
59
78
60
79
stubCallService = sinon . stub ( element , 'callService' ) . callsFake ( ( ) => {
61
- return Promise . reject ( { type : NOT_FOUND_ERROR } ) ;
80
+ return Promise . reject ( { type : NOT_FOUND_ERROR } ) ;
62
81
} ) ;
63
82
64
83
await element ;
@@ -67,25 +86,29 @@ describe('CompasExistsInElement', () => {
67
86
68
87
it ( 'the document does not exists' , ( ) => {
69
88
expect ( element . existInCompas ) . to . be . equal ( false ) ;
70
- sinon . assert . calledOnce ( stubCallService )
89
+ sinon . assert . calledTwice ( stubCallService ) ;
71
90
} ) ;
72
91
} ) ;
73
92
74
93
describe ( 'when service call returns a other error' , ( ) => {
75
94
beforeEach ( async ( ) => {
76
95
element = fixtureSync (
77
- html `< mock-compas-exists-in docId ="some-id " docName ="some-scl.scd "> </ mock-compas-exists-in > ` ) ;
96
+ html `< mock-compas-exists-in
97
+ docId ="some-id "
98
+ docName ="some-scl.scd "
99
+ > </ mock-compas-exists-in > `
100
+ ) ;
78
101
79
102
stubCallService = sinon . stub ( element , 'callService' ) . callsFake ( ( ) => {
80
- return Promise . reject ( { type : SERVER_ERROR } ) ;
103
+ return Promise . reject ( { type : SERVER_ERROR } ) ;
81
104
} ) ;
82
105
83
106
await element ;
84
107
} ) ;
85
108
86
109
it ( 'boolean stays undefined' , ( ) => {
87
110
expect ( element . existInCompas ) . to . be . undefined ;
88
- sinon . assert . calledOnce ( stubCallService )
111
+ sinon . assert . calledTwice ( stubCallService ) ;
89
112
} ) ;
90
113
} ) ;
91
114
0 commit comments