forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.js
More file actions
61 lines (56 loc) · 1.79 KB
/
data.js
File metadata and controls
61 lines (56 loc) · 1.79 KB
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
import { afterAll, beforeAll, expect, describe, it } from '@jest/globals'
import Page from '#src/frame/lib/page.js'
import languages from '#src/languages/lib/languages.js'
import nonEnterpriseDefaultVersion from '#src/versions/lib/non-enterprise-default-version.js'
import { DataDirectory } from '#src/tests/helpers/data-directory.js'
describe('data tag', () => {
let dd
const enDirBefore = languages.en.dir
beforeAll(() => {
dd = new DataDirectory({
data: {
variables: {
stuff: {
foo: 'Foo',
},
},
},
})
languages.en.dir = dd.root
})
afterAll(() => {
if (dd) dd.destroy()
languages.en.dir = enDirBefore
})
it('should render fine if data is found', async () => {
const page = await Page.init({
relativePath: 'liquid-tags/good-data-variable.md',
basePath: './src/fixtures/fixtures',
languageCode: 'en',
})
const context = {
currentVersion: nonEnterpriseDefaultVersion,
currentLanguage: 'en',
currentPath: '/en/liquid-tags/good-data-variable',
}
const rendered = await page.render(context)
// The test fixture contains:
// {% data variables.stuff.foo %}
// which we control the value of here in the test.
expect(rendered.includes('Foo')).toBeTruthy()
})
it('should throw if the data tag is used with something unrecognized', async () => {
const page = await Page.init({
relativePath: 'liquid-tags/bad-data-variable.md',
basePath: './src/fixtures/fixtures',
languageCode: 'en',
})
const context = {
currentPath: '/en/liquid-tags/bad-data-variable',
currentLanguage: 'en',
}
await expect(page.render(context)).rejects.toThrow(
"Can't find the key 'foo.bar.tipu' in the scope., line:2, col:1",
)
})
})