Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding unit tests for 'each .. of' #3183

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/pug/test/eachOf/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Proper Usage Brackets 1`] = `"<li>a</li><li>b</li><li>foo</li><li>bar</li>"`;

exports[`Proper Usage No Brackets 1`] = `"<li>a</li><li>b</li><li>foo</li><li>bar</li>"`;
3 changes: 3 additions & 0 deletions packages/pug/test/eachOf/error/left-side.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
each [key, val of users
li= key
li= val
3 changes: 3 additions & 0 deletions packages/pug/test/eachOf/error/no-brackets.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
each key, val of users
li= key
li= val
3 changes: 3 additions & 0 deletions packages/pug/test/eachOf/error/one-val.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
each [key] of users
li= key
li= val
3 changes: 3 additions & 0 deletions packages/pug/test/eachOf/error/right-side.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
each key, val] of users
li= key
li= val
52 changes: 52 additions & 0 deletions packages/pug/test/eachOf/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const pug = require('../../');

describe('Inproper Usage', () => {
test('Only left-side bracket', () => {
expect(
() => pug.compileFile(
__dirname + '/error/left-side.pug'
)
).toThrow('The value variable for each must either be a valid identifier (e.g. `item`) or a pair of identifiers in square brackets (e.g. `[key, value]`).');
})
test('Only right-side bracket', () => {
expect(
() => pug.compileFile(
__dirname + '/error/right-side.pug'
)
).toThrow('The value variable for each must either be a valid identifier (e.g. `item`) or a pair of identifiers in square brackets (e.g. `[key, value]`).');
})
test('Only one value inside brackets', () => {
expect(
() => pug.compileFile(
__dirname + '/error/one-val.pug'
)
).toThrow('The value variable for each must either be a valid identifier (e.g. `item`) or a pair of identifiers in square brackets (e.g. `[key, value]`).');
})
test('No brackets', () => {
expect(
() => pug.compileFile(
__dirname + '/error/no-brackets.pug'
)
).toThrow('The value variable for each must either be a valid identifier (e.g. `item`) or a pair of identifiers in square brackets (e.g. `[key, value]`).');
})
})
describe('Proper Usage', () => {
test('Brackets', () => {
const html = pug.renderFile(
__dirname + '/passing/brackets.pug',
{
users: new Map([['a', 'b'], ['foo', 'bar']])
}
)
expect(html).toMatchSnapshot();
})
test('No Brackets', () => {
const html = pug.renderFile(
__dirname + '/passing/no-brackets.pug',
{
users: new Map([['a', 'b'], ['foo', 'bar']])
}
)
expect(html).toMatchSnapshot();
})
})
3 changes: 3 additions & 0 deletions packages/pug/test/eachOf/passing/brackets.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
each [key, val] of users
li= key
li= val
3 changes: 3 additions & 0 deletions packages/pug/test/eachOf/passing/no-brackets.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
each data of users
li= data[0]
li= data[1]