Skip to content

Commit 2b5411f

Browse files
committed
fix tests
1 parent e5e6b44 commit 2b5411f

File tree

2 files changed

+61
-53
lines changed

2 files changed

+61
-53
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`test case code emitter should append the snapshot of the setup and teardown hooks to the test case 1`] = `
4+
Object {
5+
"function": "tests[\\"example test case\\"] = async (driver, vars, opts = {}) => {}",
6+
"id": "1",
7+
"name": "example test case",
8+
"test": "it(\\"example test case\\", async () => {setup codemore setupawait tests[\\"example test case\\"](driver, vars);expect(true).toBeTruthy();teardown codemore teardown});",
9+
}
10+
`;
11+
12+
exports[`test case code emitter should emit a test with a single command 1`] = `
13+
Object {
14+
"function": "tests[\\"example test case\\"] = async (driver, vars, opts = {}) => {await driver.get((new URL(\\"/\\", BASE_URL)).href);}",
15+
"id": "1",
16+
"name": "example test case",
17+
"test": "it(\\"example test case\\", async () => {await tests[\\"example test case\\"](driver, vars);expect(true).toBeTruthy();});",
18+
}
19+
`;
20+
21+
exports[`test case code emitter should emit a test with multiple commands 1`] = `
22+
Object {
23+
"function": "tests[\\"example test case\\"] = async (driver, vars, opts = {}) => {await driver.get((new URL(\\"/\\", BASE_URL)).href);await driver.get((new URL(\\"/test\\", BASE_URL)).href);await driver.get((new URL(\\"/example\\", BASE_URL)).href);}",
24+
"id": "1",
25+
"name": "example test case",
26+
"test": "it(\\"example test case\\", async () => {await tests[\\"example test case\\"](driver, vars);expect(true).toBeTruthy();});",
27+
}
28+
`;
29+
30+
exports[`test case code emitter should emit an empty test case 1`] = `
31+
Object {
32+
"function": "tests[\\"example test case\\"] = async (driver, vars, opts = {}) => {}",
33+
"id": "1",
34+
"name": "example test case",
35+
"test": "it(\\"example test case\\", async () => {await tests[\\"example test case\\"](driver, vars);expect(true).toBeTruthy();});",
36+
}
37+
`;
38+
39+
exports[`test case code emitter should send the snapshot to the command 1`] = `
40+
Object {
41+
"function": "tests[\\"example test case\\"] = async (driver, vars, opts = {}) => {command code}",
42+
"id": "1",
43+
"name": "example test case",
44+
"test": "it(\\"example test case\\", async () => {await tests[\\"example test case\\"](driver, vars);expect(true).toBeTruthy();});",
45+
}
46+
`;

packages/selianize/__tests__/testcase.spec.js

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ describe('test case code emitter', () => {
2525
name: 'example test case',
2626
commands: [],
2727
}
28-
return expect(TestCaseEmitter.emit(test)).resolves.toEqual({
29-
id: '1',
30-
name: 'example test case',
31-
test: `it("${
32-
test.name
33-
}", async () => {await tests["example test case"](driver, vars);expect(true).toBeTruthy();});`,
34-
function: 'tests["example test case"] = async (driver, vars, opts) => {}',
35-
})
28+
return expect(TestCaseEmitter.emit(test)).resolves.toMatchSnapshot()
3629
})
3730
it('should emit a test with a single command', () => {
3831
const test = {
@@ -46,16 +39,7 @@ describe('test case code emitter', () => {
4639
},
4740
],
4841
}
49-
return expect(TestCaseEmitter.emit(test)).resolves.toEqual({
50-
id: '1',
51-
name: 'example test case',
52-
test: `it("${
53-
test.name
54-
}", async () => {await tests["example test case"](driver, vars);expect(true).toBeTruthy();});`,
55-
function: `tests["example test case"] = async (driver, vars, opts) => {await driver.get((new URL("${
56-
test.commands[0].target
57-
}", BASE_URL)).href);}`,
58-
})
42+
return expect(TestCaseEmitter.emit(test)).resolves.toMatchSnapshot()
5943
})
6044
it('should emit a test with multiple commands', () => {
6145
const test = {
@@ -79,20 +63,7 @@ describe('test case code emitter', () => {
7963
},
8064
],
8165
}
82-
return expect(TestCaseEmitter.emit(test)).resolves.toEqual({
83-
id: '1',
84-
name: 'example test case',
85-
test: `it("${
86-
test.name
87-
}", async () => {await tests["example test case"](driver, vars);expect(true).toBeTruthy();});`,
88-
function: `tests["example test case"] = async (driver, vars, opts) => {await driver.get((new URL("${
89-
test.commands[0].target
90-
}", BASE_URL)).href);await driver.get((new URL("${
91-
test.commands[1].target
92-
}", BASE_URL)).href);await driver.get((new URL("${
93-
test.commands[2].target
94-
}", BASE_URL)).href);}`,
95-
})
66+
return expect(TestCaseEmitter.emit(test)).resolves.toMatchSnapshot()
9667
})
9768
it('should reject a test with failed commands', () => {
9869
const test = {
@@ -158,7 +129,7 @@ describe('test case code emitter', () => {
158129
test:
159130
'it("silence", async () => {await tests["silence"](driver, vars);expect(true).toBeTruthy();});',
160131
function:
161-
'tests["silence"] = async (driver, vars, opts) => {throw new Error("Unknown command doesntExist");}',
132+
'tests["silence"] = async (driver, vars, opts = {}) => {throw new Error("Unknown command doesntExist");}',
162133
})
163134
})
164135
it('should emit an empty snapshot for an empty test case when skipStdLibEmitting is set', () => {
@@ -167,7 +138,7 @@ describe('test case code emitter', () => {
167138
name: 'example test case',
168139
commands: [],
169140
}
170-
expect(
141+
return expect(
171142
TestCaseEmitter.emit(test, { skipStdLibEmitting: true })
172143
).resolves.toEqual({})
173144
})
@@ -183,7 +154,7 @@ describe('test case code emitter', () => {
183154
},
184155
],
185156
}
186-
expect(
157+
return expect(
187158
TestCaseEmitter.emit(test, { skipStdLibEmitting: true })
188159
).resolves.toEqual({})
189160
})
@@ -201,7 +172,7 @@ describe('test case code emitter', () => {
201172
],
202173
}
203174
CommandEmitter.registerEmitter('aNewCommand', () => 'command code')
204-
expect(
175+
return expect(
205176
TestCaseEmitter.emit(test, { skipStdLibEmitting: true })
206177
).resolves.toEqual({
207178
id: '1',
@@ -234,14 +205,9 @@ describe('test case code emitter', () => {
234205
setupHooks: [],
235206
teardownHooks: [],
236207
}
237-
expect(TestCaseEmitter.emit(test, undefined, snapshot)).resolves.toEqual({
238-
id: '1',
239-
name: 'example test case',
240-
test:
241-
'it("example test case", async () => {await tests["example test case"](driver, vars);expect(true).toBeTruthy();});',
242-
function:
243-
'tests["example test case"] = async (driver, vars, opts) => {command code}',
244-
})
208+
return expect(
209+
TestCaseEmitter.emit(test, undefined, snapshot)
210+
).resolves.toMatchSnapshot()
245211
})
246212
it('should emit a snapshot for a test case with setup and teardown hooks when skipStdLibEmitting is set', () => {
247213
const test = {
@@ -253,7 +219,7 @@ describe('test case code emitter', () => {
253219
setup: 'setup code',
254220
teardown: 'teardown code',
255221
}))
256-
expect(
222+
return expect(
257223
TestCaseEmitter.emit(test, { skipStdLibEmitting: true })
258224
).resolves.toEqual({
259225
id: '1',
@@ -274,7 +240,7 @@ describe('test case code emitter', () => {
274240
setup: '',
275241
teardown: '',
276242
}))
277-
expect(
243+
return expect(
278244
TestCaseEmitter.emit(test, { skipStdLibEmitting: true })
279245
).resolves.toEqual({
280246
id: '1',
@@ -296,12 +262,8 @@ describe('test case code emitter', () => {
296262
setupHooks: ['more setup'],
297263
teardownHooks: ['more teardown'],
298264
}
299-
expect(TestCaseEmitter.emit(test, undefined, snapshot)).resolves.toEqual({
300-
id: '1',
301-
name: 'example test case',
302-
test:
303-
'it("example test case", async () => {setup codemore setupawait tests["example test case"](driver, vars);expect(true).toBeTruthy();teardown codemore teardown});',
304-
function: 'tests["example test case"] = async (driver, vars, opts) => {}',
305-
})
265+
return expect(
266+
TestCaseEmitter.emit(test, undefined, snapshot)
267+
).resolves.toMatchSnapshot()
306268
})
307269
})

0 commit comments

Comments
 (0)