Skip to content

Instantly share code, notes, and snippets.

@rstacruz
Last active April 22, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rstacruz/2e2189d5f82feec4537b349ec1ef43ee to your computer and use it in GitHub Desktop.
Save rstacruz/2e2189d5f82feec4537b349ec1ef43ee to your computer and use it in GitHub Desktop.
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)
})
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