@@ -21,6 +21,7 @@ const sassBootstrap = `
2121
2222 // Emulates data from _settings/spacing.scss
2323 $govuk-spacing-points: (
24+ 0: 0,
2425 2: 15px
2526 );
2627
@@ -52,7 +53,22 @@ describe('@function govuk-spacing', () => {
5253 top: 15px; }` )
5354 } )
5455
55- it ( 'throws an exception when passed anything other than a number' , async ( ) => {
56+ it ( 'returns CSS for a property based on a negative spacing point' , async ( ) => {
57+ const sass = `
58+ ${ sassBootstrap }
59+
60+ .foo {
61+ top: govuk-spacing(-2)
62+ }`
63+
64+ const results = await renderSass ( { data : sass , ...sassConfig } )
65+
66+ expect ( results . css . toString ( ) . trim ( ) ) . toBe ( outdent `
67+ .foo {
68+ top: -15px; }` )
69+ } )
70+
71+ it ( 'throws an error when passed anything other than a number' , async ( ) => {
5672 const sass = `
5773 ${ sassBootstrap }
5874
@@ -66,6 +82,51 @@ describe('@function govuk-spacing', () => {
6682 'Expected a number (integer), but got a string.'
6783 )
6884 } )
85+
86+ it ( 'throws an error when passed a non-existent point' , async ( ) => {
87+ const sass = `
88+ ${ sassBootstrap }
89+
90+ .foo {
91+ top: govuk-spacing(999)
92+ }`
93+
94+ await expect ( renderSass ( { data : sass , ...sassConfig } ) )
95+ . rejects
96+ . toThrow (
97+ 'Unknown spacing variable `999`. Make sure you are using a point from the spacing scale in `_settings/spacing.scss`.'
98+ )
99+ } )
100+
101+ it ( 'throws an error when passed a non-existent negative point' , async ( ) => {
102+ const sass = `
103+ ${ sassBootstrap }
104+
105+ .foo {
106+ top: govuk-spacing(-999)
107+ }`
108+
109+ await expect ( renderSass ( { data : sass , ...sassConfig } ) )
110+ . rejects
111+ . toThrow (
112+ 'Unknown spacing variable `999`. Make sure you are using a point from the spacing scale in `_settings/spacing.scss`.'
113+ )
114+ } )
115+
116+ it ( 'handles negative zero' , async ( ) => {
117+ const sass = `
118+ ${ sassBootstrap }
119+
120+ .foo {
121+ top: govuk-spacing(-0)
122+ }`
123+
124+ const results = await renderSass ( { data : sass , ...sassConfig } )
125+
126+ expect ( results . css . toString ( ) . trim ( ) ) . toBe ( outdent `
127+ .foo {
128+ top: 0; }` )
129+ } )
69130} )
70131
71132describe ( '@mixin _govuk-responsive-spacing' , ( ) => {
0 commit comments