generated from rdimascio/blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan DiMascio
committed
Jul 18, 2020
1 parent
f6f9e1c
commit 2d8b317
Showing
7 changed files
with
136 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable import/no-anonymous-default-export */ | ||
|
||
export default { | ||
files: ["src/__tests__/index.test.js"], | ||
verbose: true, | ||
ignoredByWatcher: ["{coverage,examples/**"], | ||
require: ["esm", "./src/__tests__/_setup-browser-env.js"], | ||
nodeArguments: ["--experimental-modules"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable import/no-anonymous-default-export */ | ||
|
||
export default { | ||
files: ["src/__tests__/index.node.test.js"], | ||
verbose: true, | ||
ignoredByWatcher: ["{coverage,examples/**"], | ||
require: ["esm"], | ||
nodeArguments: ["--experimental-modules"], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
const browserEnv = require('browser-env'); | ||
browserEnv(['window', 'document']); | ||
browserEnv(['window', 'document', 'DOMParser']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import test from 'ava'; | ||
import getAttributes from '..'; | ||
|
||
test('`getAttributes.parse()` parses attributes from a string', t => { | ||
const string = '<div id="ava" data-brand-icon="ava" data-brand-color="dark"></div>'; | ||
const attrs = getAttributes.parse(string); | ||
|
||
t.deepEqual(attrs, { | ||
'data-brand-icon': 'ava', | ||
'data-brand-color': 'dark', | ||
id: 'ava' | ||
}); | ||
}); | ||
|
||
test('`getAttributes.parse()` handles empty attributes from a string', t => { | ||
const string = '<div id="ava" empty-attribute data-brand-icon="ava" data-brand-color="dark"></div>'; | ||
const attrs = getAttributes.parse(string); | ||
|
||
t.deepEqual(attrs, { | ||
'data-brand-icon': 'ava', | ||
'data-brand-color': 'dark', | ||
'empty-attribute': '', | ||
id: 'ava' | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* eslint-disable no-undef */ | ||
|
||
import test from 'ava'; | ||
import getAttributes from '..'; | ||
|
||
test('`getAttributes.parse()` parses attributes from a DOM element', t => { | ||
const div = document.createElement('div'); | ||
div.dataset.brandIcon = 'ava'; | ||
div.dataset.brandColor = 'dark'; | ||
div.id = 'ava'; | ||
|
||
document.body.append(div); | ||
|
||
const attrs = getAttributes.parse(document.querySelector('#ava')); | ||
|
||
t.deepEqual(attrs, { | ||
'data-brand-icon': 'ava', | ||
'data-brand-color': 'dark', | ||
id: 'ava' | ||
}); | ||
}); | ||
|
||
test('`getAttributes.parse()` parses attributes from a string', t => { | ||
const string = '<div id="ava" data-brand-icon="ava" data-brand-color="dark"></div>'; | ||
const attrs = getAttributes.parse(string); | ||
|
||
t.deepEqual(attrs, { | ||
'data-brand-icon': 'ava', | ||
'data-brand-color': 'dark', | ||
id: 'ava' | ||
}); | ||
}); | ||
|
||
test('`getAttributes.parse()` fails when given an empty string', t => { | ||
const error = t.throws(() => { | ||
getAttributes.parse(''); | ||
}, {instanceOf: ReferenceError}); | ||
|
||
t.is(error.message, 'The string given to `getAttributes.parse()` is empty.'); | ||
}); | ||
|
||
test('`getAttributes.parse()` fails when given a type other than string or node', t => { | ||
const types = [[], {}, true, 3]; | ||
|
||
// Two assertions per item: `t.throws()` and `t.is()`. | ||
t.plan(types.length * 2); | ||
|
||
types.forEach(type => { | ||
const error = t.throws(() => { | ||
getAttributes.parse(type); | ||
}, {instanceOf: TypeError}); | ||
|
||
t.is(error.message, '`getAttributes.parse()` only accepts strings and nodes. An ' + typeof type + ' was given.'); | ||
}); | ||
}); | ||
|
||
test('`getAttributes.stringify()` returns a string when given a string', t => { | ||
const attrString = getAttributes.stringify('Wow cool test'); | ||
|
||
t.is(attrString, 'Wow cool test'); | ||
}); | ||
|
||
test('`getAttributes.stringify()` returns a string when given array', t => { | ||
const arrayToString = getAttributes.stringify(['Wow', 'cool', 'test']); | ||
|
||
t.is(arrayToString, 'Wow cool test'); | ||
}); | ||
|
||
test('`getAttributes.stringify()` returns a string when given object', t => { | ||
const objectToString = getAttributes.stringify({ | ||
'data-brand-icon': 'ava', | ||
'data-brand-color': 'dark', | ||
'empty-attribute': '' | ||
}); | ||
|
||
t.is(objectToString, 'data-brand-icon="ava" data-brand-color="dark" empty-attribute'); | ||
}); | ||
|
||
test('`getAttributes.stringify()` fails when given an empty string', t => { | ||
const error = t.throws(() => { | ||
getAttributes.stringify(''); | ||
}, {instanceOf: ReferenceError}); | ||
|
||
t.is(error.message, 'Cannot stringify undefined.'); | ||
}); |