Last active
April 22, 2017 15:28
-
-
Save rstacruz/2e2189d5f82feec4537b349ec1ef43ee to your computer and use it in GitHub Desktop.
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
import $ from 'jquery' | |
import onmount from 'onmount' | |
/* | |
* Simple behavior to show a toast notification | |
* (simplified for the sake of illustration) | |
*/ | |
onmount('[data-js-notice-notification]', function () { | |
const $this = $(this) | |
const $toast = $('<div id="toast-container">') | |
.html($this.data('message')) | |
$('body').append($toast) | |
}) |
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
import $ from 'jquery' | |
import onmount from 'onmount' | |
import '../notice_notification' | |
let $div | |
beforeEach(() => { | |
$div = $('<div>').appendTo('body') | |
}) | |
afterEach(() => { | |
$div.remove() | |
onmount() | |
}) | |
test('data-js-notice-notification', () => { | |
// Mock a notice notification | |
$('<noscript data-js-notice-notification data-message="Hello" />') | |
.appendTo($div) | |
// Trigger behaviors | |
onmount() | |
// Assert that #toast-container is created | |
const $toast = $('#toast-container') | |
expect($toast[0].outerHTML).toMatchSnapshot() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment