Skip to content

Commit

Permalink
Update alert() assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-white committed Jan 16, 2021
1 parent c01db03 commit cad1dd1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
11 changes: 5 additions & 6 deletions test/assertions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import should from 'should';

import Alert from '../src/components/alert.vue';
import { unwrapElement } from './util/util';

// Asserts that an element is not individually hidden and that all its ancestors
Expand Down Expand Up @@ -42,9 +41,9 @@ should.Assertion.add('focused', function focused() {
});

should.Assertion.add('alert', function assertAlert(type = undefined, message = undefined) {
const alert = this.obj.first(Alert);
alert.vm.$el.style.display.should.equal('');
if (type != null) alert.hasClass(`alert-${type}`).should.be.true();
if (message != null)
alert.first('.alert-message').text().should.match(message);
this.params = { operator: 'to show an alert' };
const { alert } = this.obj.vm.$store.state;
alert.state.should.be.true();
if (type != null) alert.type.should.equal(type);
if (message != null) alert.message.should.match(message);
});
27 changes: 27 additions & 0 deletions test/components/alert.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Alert from '../../src/components/alert.vue';

import store from '../../src/store';

import { mount } from '../util/lifecycle';
import { trigger } from '../util/event';

describe('Alert', () => {
beforeEach(() => {
store.commit('setAlert', { type: 'info', message: 'Something happened!' });
});

it('shows the message', () => {
const text = mount(Alert).first('.alert-message').text();
text.should.equal('Something happened!');
});

it('adds a contextual class', () => {
mount(Alert).hasClass('alert-info').should.be.true();
});

it('clicking the .close button hides the alert', async () => {
const alert = mount(Alert);
await trigger.click(alert, '.close');
alert.should.be.hidden();
});
});

0 comments on commit cad1dd1

Please sign in to comment.