-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
43 lines (33 loc) · 1.06 KB
/
test.js
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
const lookup = require('./dist/index.node.js')
test('happy path for a known word', async () => {
const result = await lookup('pomology')
expect(result).toHaveProperty('query', 'pomology')
expect(result).toHaveProperty('title', 'Pomology')
expect(result).toHaveProperty('description')
expect(result).toHaveProperty('extract')
expect(result).toHaveProperty('extract_html')
})
test('unhappy path with a nonexistent term', async () => {
const result = await lookup('pomologyyyyyyyyyyyy')
expect(result).toBeNull()
})
test('alternate languages', async () => {
const result = await lookup('Muñeca', 'es')
expect(result.extract).toMatch('Una muñeca es una figura')
})
// cli tests
const { spawn } = require('child_process')
test('cli', async (done) => {
const reverse = spawn('node', ['cli.js', 'pomology'])
const chunks = []
reverse.stdout.on('data', (chunk) => {
chunks.push(chunk)
});
reverse.stdout.on('end', () => {
const output = Buffer
.concat(chunks)
.toString()
expect(output).toContain('Pomology:')
done()
});
});