Skip to content

Commit

Permalink
Test 'to have attributes' with array argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed Mar 3, 2015
1 parent 8abcb6f commit 5d91d2d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
if (typeof cmp === 'string') {
expect(attrs, '[not] to [only] have keys', Array.prototype.slice.call(arguments, 2));
} else if (Array.isArray(cmp)) {
expect(attrs, '[not] to have keys', cmp);
expect(attrs, '[not] to [only] have keys', cmp);
}
});
}
Expand Down
59 changes: 56 additions & 3 deletions test/unexpected-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('unexpected-dom', function () {
expect(function () {
expect(el, 'to only have attributes', 'id');
}, 'to throw exception', function (err) {
expect(err.output.toString(), 'to match', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> to only have attributes \'id\'');
expect(err.output.toString(), 'to be', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> to only have attributes \'id\'');
});
});

Expand All @@ -70,7 +70,7 @@ describe('unexpected-dom', function () {
expect(function () {
expect(el, 'to have attributes', 'id', 'foo');
}, 'to throw exception', function (err) {
expect(err.output.toString(), 'to match', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> to have attributes \'id\', \'foo\'');
expect(err.output.toString(), 'to be', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> to have attributes \'id\', \'foo\'');
});
});

Expand All @@ -87,7 +87,60 @@ describe('unexpected-dom', function () {
expect(function () {
expect(el, 'not to have attributes', 'id');
}, 'to throw exception', function (err) {
expect(err.output.toString(), 'to match', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> not to have attributes \'id\'');
expect(err.output.toString(), 'to be', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> not to have attributes \'id\'');
});
});
});

describe('array comparison', function () {
it('should match exact arguments', function () {
this.body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';

expect(this.body.firstChild, 'to only have attributes', ['id', 'class', 'data-info', 'disabled']);
});

it('should fail on exact arguments not met', function () {
this.body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';
var el = this.body.firstChild;

expect(function () {
expect(el, 'to only have attributes', ['id']);
}, 'to throw exception', function (err) {
expect(err.output.toString(), 'to be', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> to only have attributes [ \'id\' ]');
});
});

it('should match partial arguments', function () {
this.body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';

expect(this.body.firstChild, 'to have attributes', ['id', 'class']);
});

it('should fail on partial arguments not met', function () {
this.body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';
var el = this.body.firstChild;

expect(function () {
expect(el, 'to have attributes', ['id', 'foo']);
}, 'to throw exception', function (err) {
expect(err.output.toString(), 'to be', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> to have attributes [ \'id\', \'foo\' ]');
});
});

it('should match negative arguments', function () {
this.body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';

expect(this.body.firstChild, 'not to have attributes', ['foo', 'bar']);
});

it('should fail on negative partial arguments met', function () {
this.body.innerHTML = '<button id="foo" class="bar" data-info="baz" disabled>Press me</button>';
var el = this.body.firstChild;

expect(function () {
expect(el, 'not to have attributes', ['id']);
}, 'to throw exception', function (err) {
expect(err.output.toString(), 'to be', 'expected <button class="bar" data-info="baz" disabled="" id="foo"/> not to have attributes [ \'id\' ]');
});
});
});
Expand Down

0 comments on commit 5d91d2d

Please sign in to comment.