Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 8bf67b8

Browse files
committed
create eventUtilTest
1 parent 3d2b641 commit 8bf67b8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

js/lib/eventUtil.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ module.exports.isForSecondaryAction = (e) =>
1111

1212
module.exports.eventElHasAncestorWithClasses = (e, classesToCheck) => {
1313
// DO NOT ADD NEW CHECKS USING THIS METHOD
14-
// classNames are changed from dev to prod by Aphrodite
14+
// classNames are changed from dev to prod by Aphrodite est. v1.2.3
1515
// and new code will not work. Consider using dataset attribute instead.
16+
// See issue #10029 for a breaking example.
1617
// ....
1718
// TODO deprecate this method.
1819
let node = e.target

test/unit/js/lib/eventUtilTest.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
/* global describe, it */
5+
6+
const eventUtil = require('../../../../js/lib/eventUtil')
7+
const assert = require('assert')
8+
9+
require('../../braveUnit')
10+
11+
describe('eventUtil', function () {
12+
describe('elementHasDataset', function () {
13+
let datasetToTest
14+
let node = { dataset: { nespresso: true } }
15+
16+
it('returns false if node dataset do not match', function () {
17+
datasetToTest = ['starbucks', 'keurig']
18+
assert.equal(eventUtil.elementHasDataset(node, datasetToTest), false)
19+
})
20+
it('returns true if node dataset match the provided dataset array', function () {
21+
datasetToTest = ['wow', 'such', 'nespresso', 'very', 'amazing']
22+
assert.equal(eventUtil.elementHasDataset(node, datasetToTest), true)
23+
})
24+
it('can accept strings for the dataset to match against', function () {
25+
datasetToTest = 'nespresso'
26+
assert.equal(eventUtil.elementHasDataset(node, datasetToTest), true)
27+
})
28+
it('can not accept partial string match', function () {
29+
datasetToTest = ['nespressomnibox']
30+
assert.equal(eventUtil.elementHasDataset(node, datasetToTest), false)
31+
})
32+
it('returns false if node do not provide a dataset', function () {
33+
node = delete node.dataset
34+
datasetToTest = ['nespresso']
35+
assert.equal(eventUtil.elementHasDataset(node, datasetToTest), false)
36+
})
37+
})
38+
})

0 commit comments

Comments
 (0)