-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsass.test.js
116 lines (92 loc) · 2.68 KB
/
sass.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* eslint-env jest */
const glob = require('glob')
const sass = require('node-sass')
const { render } = require('./helpers')
// Test that the index.css entry point compiles without throwing any errors.
describe('sass/index.scss', () => {
it('compiles to CSS', () => {
return render({
file: 'sass/index.scss'
})
})
})
// Test that components can be compiled individually without throwing errors.
describe('sass/components/', () => {
const components = glob.sync('sass/components/*.scss')
it.each(components)('%s compiles to CSS', (file) => {
return render({ file })
})
})
// Test that the settings file does not output any CSS
describe('sass/_settings.scss', () => {
it('does not output CSS', async () => {
return render({
file: 'sass/_settings.scss'
}).then(output => {
expect(output.css.toString()).toEqual('')
})
})
})
// Testing Sass functions
describe('functions/_half.scss', () => {
it('halves a given even number', async () => {
const data = `
@import "functions/half";
.foo {
width: half(10px);
}
`
return render({ data }).then(output => {
expect(output.css.toString().trim()).toBe('.foo { width: 5px; }')
})
})
it('errors when trying to half something that is not a number', async () => {
const data = `
@import "functions/half";
.foo {
width: half("trollolol");
}
`
return expect(render({ data })).rejects.toThrow(
'Cannot half something which is not a number!'
)
})
it('warns when result is not a whole number', async () => {
const data = `
@import "functions/half";
.foo {
width: half(9px);
}
`
// Create a mock warn function that we can use to override the native @warn
// function, that we can make assertions about post-render.
const mockWarnFunction = jest.fn()
.mockReturnValue(sass.NULL)
return render({
data,
functions: {
'@warn': mockWarnFunction
}
}).then(() => {
// Expect our mocked @warn function to have been called once with a single
// argument, which should be the deprecation notice
return expect(mockWarnFunction.mock.calls[0][0].getValue())
.toEqual('Halving 9px returns a non-whole number')
})
})
})
// Testing mixins
describe('mixins/_enhance.scss', () => {
it('makes everything awesome', async () => {
const data = `
@import "mixins/enhance";
.foo {
@include enhance;
}
`
return render({ data }).then(output => {
expect(output.css.toString().trim())
.toBe(".foo { font-family: 'Comic Sans MS' !important; color: hotpink !important; }")
})
})
})