Skip to content

Commit

Permalink
Fix tests and lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Jan 14, 2019
1 parent eeb42cd commit 5ade923
Show file tree
Hide file tree
Showing 57 changed files with 1,095 additions and 920 deletions.
31 changes: 19 additions & 12 deletions __tests__/applyAtRule.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import postcss from 'postcss'
import plugin from '../src/lib/substituteClassApplyAtRules'
import generateUtilities from '../src/legacy/generateUtilities'
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
import processPlugins from '../src/util/processPlugins'
import defaultPlugins from '../src/defaultPlugins'
import defaultConfig from '../defaultConfig.stub.js'

const defaultUtilities = generateUtilities(defaultConfig, [])
const { utilities: defaultUtilities } = processPlugins(defaultPlugins(defaultConfig), defaultConfig)

function run(input, config = defaultConfig, utilities = defaultUtilities) {
return postcss([plugin(config, utilities)]).process(input, { from: undefined })
return postcss([substituteClassApplyAtRules(config, utilities)]).process(input, {
from: undefined,
})
}

test("it copies a class's declarations into itself", () => {
Expand Down Expand Up @@ -206,10 +209,12 @@ test('you can apply utility classes without using the given prefix', () => {
experiments: { shadowLookup: true },
}

return run(input, config, generateUtilities(config, [])).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
})

test('you can apply utility classes without using the given prefix when using a function for the prefix', () => {
Expand All @@ -232,8 +237,10 @@ test('you can apply utility classes without using the given prefix when using a
experiments: { shadowLookup: true },
}

return run(input, config, generateUtilities(config, [])).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
})
105 changes: 51 additions & 54 deletions __tests__/containerPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,13 @@ function config(overrides) {
xl: '1200px',
},
options: {
prefix: "",
prefix: '',
important: false,
separator: ":"
}
separator: ':',
},
})
}

function processPluginsWithValidConfig(config) {
return processPlugins(
_.defaultsDeep(config, {
screens: {
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
},
options: {
prefix: '',
important: false,
separator: ':',
},
})
)
}

test.only('options are not required', () => {
const { components } = processPlugins([container()], config())

Expand All @@ -62,14 +44,17 @@ test.only('options are not required', () => {
})

test.only('screens can be specified explicitly', () => {
const { components } = processPlugins([
container({
screens: {
sm: '400px',
lg: '500px',
},
}),
], config())
const { components } = processPlugins(
[
container({
screens: {
sm: '400px',
lg: '500px',
},
}),
],
config()
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -83,11 +68,14 @@ test.only('screens can be specified explicitly', () => {
})

test.only('screens can be an array', () => {
const { components } = processPlugins([
container({
screens: ['400px', '500px'],
}),
], config())
const { components } = processPlugins(
[
container({
screens: ['400px', '500px'],
}),
],
config()
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -101,11 +89,14 @@ test.only('screens can be an array', () => {
})

test.only('the container can be centered by default', () => {
const { components } = processPlugins([
container({
center: true,
}),
], config())
const { components } = processPlugins(
[
container({
center: true,
}),
],
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand All @@ -129,11 +120,14 @@ test.only('the container can be centered by default', () => {
})

test.only('horizontal padding can be included by default', () => {
const { components } = processPlugins([
container({
padding: '2rem',
}),
], config())
const { components } = processPlugins(
[
container({
padding: '2rem',
}),
],
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand All @@ -157,16 +151,19 @@ test.only('horizontal padding can be included by default', () => {
})

test.only('setting all options at once', () => {
const { components } = processPlugins([
container({
screens: {
sm: '400px',
lg: '500px',
},
center: true,
padding: '2rem',
}),
], config())
const { components } = processPlugins(
[
container({
screens: {
sm: '400px',
lg: '500px',
},
center: true,
padding: '2rem',
}),
],
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand Down
Loading

0 comments on commit 5ade923

Please sign in to comment.