forked from TheNoim/fastify-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
76 lines (59 loc) · 1.86 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const Fastify = require('fastify');
const fetch = require('node-fetch');
const nanoid = require('nanoid');
test('fastify should have decorator nuxt', done => {
const fastify = Fastify();
const pl = require('./index');
fastify.register(pl, {config: { dev: false }}).after(err => {
expect(err).toBeFalsy();
expect(fastify.nuxt).toBeDefined();
done();
});
fastify.close();
});
test('should throw if no config is provided', done => {
const fastify = Fastify();
const pl = require('./index');
fastify.register(pl).after(err => {
expect(err).toBeDefined();
expect(err.message).toBeDefined();
expect(err.message).toEqual('You need to provide a nuxt config.');
done();
});
fastify.close();
});
test('page should be reach able', done => {
const fastify = Fastify();
const pl = require('./index');
fastify.register(pl, {config: { dev: false }}).after(err => {
expect(err).toBeFalsy();
fastify.nuxt('/');
});
fastify.listen(1337, async err => {
expect(err).toBeFalsy();
const r = await fetch('http://127.0.0.1:1337/');
const data = await r.text();
expect(data).toContain('Nice to meet you');
fastify.close(() => {
done();
});
});
}, 15000);
test('params should work', done => {
const fastify = Fastify();
const pl = require('./index');
const id = nanoid();
fastify.register(pl, {config: { dev: false }}).after(err => {
expect(err).toBeFalsy();
fastify.nuxt('/test/:id');
});
fastify.listen(1337, async err => {
expect(err).toBeFalsy();
const r = await fetch('http://127.0.0.1:1337/test/' + id);
const data = await r.text();
expect(data).toContain(id);
fastify.close(() => {
done();
});
});
}, 15000);