Skip to content

Commit

Permalink
WIP add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
williamkennedy committed Nov 27, 2020
1 parent 046701e commit 3c73a04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
16 changes: 0 additions & 16 deletions __tests__/setup.js

This file was deleted.

28 changes: 9 additions & 19 deletions __tests__/toggle_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
import { Application, Controller } from "stimulus";
import Toggle from "toggle";

const emitEvent = (element, eventType) => {
const event = new Event(eventType);
element.dispatchEvent(event);
};

describe("ToggleController", () => {
describe(".toggledClass", () => {
describe("#toggle", () => {
beforeEach(() => {
document.body.innerHTML = `<div data-controller='toggle' class="m-2">
<div data-action='click->toggle#toggle' class="bg-gray-900 text-white p-6">
document.body.innerHTML = `<div data-controller='toggle' data-toggle-class='toggledClass' class="m-2">
<div id='toggleAction' data-action='click->toggle#toggle' class="bg-gray-900 text-white p-6">
What is the question?
</div>
<div id='toggleTarget' data-target='toggle.toggleable' class="m-4 hidden">
<div id='toggleTarget' data-target='toggle.toggleable' class="m-4">
<p>This is the answer</p>
</div>
</div>`
Expand All @@ -25,16 +20,11 @@ describe("ToggleController", () => {
});


it("toggles hidden class from toggle.toggleable", () => {
let toggleTarget = document.getElementById('toggleTarget')
const evt = new Event('click', { bubbles: true, cancelable: false, composed: false });
toggleTarget.stimulate('click');
console.log(toggleTarget.className)
toggleTarget.dispatchEvent(evt)
toggleTarget.stimulate('click');
console.log(toggleTarget.className)
expect(toggleTarget.className.includes('hidden')).toEqual(false)

it("adds active class to toggle.toggleable", () => {
const toggleAction = document.getElementById('toggleAction')
const toggleTarget = document.getElementById('toggleTarget')
toggleAction.click()
expect(toggleTarget.className.includes('toggledClass')).toEqual(true)
});
});
});
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
"test": "jest"
},
"jest": {
"setupFiles": [
"./__tests__/setup.js"
],
"testRegex": ".*_test.js",
"roots": [
"__tests__"
Expand All @@ -48,7 +45,6 @@
},
"devDependencies": {
"babel-jest": "^26.6.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"jest": "^26.6.3",
"microbundle": "^0.12.3",
Expand Down

0 comments on commit 3c73a04

Please sign in to comment.