Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {assert} from 'chai'; |
| 6 | import sinon from 'sinon'; |
| 7 | import {ChopsToggle} from './chops-toggle.js'; |
| 8 | |
| 9 | let element; |
| 10 | |
| 11 | describe('chops-toggle', () => { |
| 12 | beforeEach(() => { |
| 13 | element = document.createElement('chops-toggle'); |
| 14 | document.body.appendChild(element); |
| 15 | }); |
| 16 | |
| 17 | afterEach(() => { |
| 18 | document.body.removeChild(element); |
| 19 | }); |
| 20 | |
| 21 | it('initializes', () => { |
| 22 | assert.instanceOf(element, ChopsToggle); |
| 23 | }); |
| 24 | |
| 25 | it('clicking toggle dispatches checked-change event', async () => { |
| 26 | element.checked = false; |
| 27 | sinon.stub(window, 'CustomEvent'); |
| 28 | sinon.stub(element, 'dispatchEvent'); |
| 29 | |
| 30 | await element.updateComplete; |
| 31 | |
| 32 | element.click(); |
| 33 | |
| 34 | assert.deepEqual(window.CustomEvent.args[0][0], 'checked-change'); |
| 35 | assert.deepEqual(window.CustomEvent.args[0][1], { |
| 36 | detail: {checked: true}, |
| 37 | }); |
| 38 | |
| 39 | assert.isTrue(window.CustomEvent.calledOnce); |
| 40 | assert.isTrue(element.dispatchEvent.calledOnce); |
| 41 | |
| 42 | window.CustomEvent.restore(); |
| 43 | element.dispatchEvent.restore(); |
| 44 | }); |
| 45 | }); |