blob: 423c993060a0042bd588dd052a8e3d7d982ce7ff [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// 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
5import {assert} from 'chai';
6import sinon from 'sinon';
7import {ChopsToggle} from './chops-toggle.js';
8
9let element;
10
11describe('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});