-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { addClasses } from "../../src"; | ||
|
||
describe("addClasses", () => { | ||
afterEach(clearFixtures); | ||
|
||
it("adds classes from given list which not added to element early", () => { | ||
useFixture(`<div class="root foo"></div>`); | ||
|
||
const subject = document.querySelector(".root"); | ||
|
||
expect(subject.classList.contains("foo")).toBe(true); | ||
expect(subject.classList.contains("bar")).toBe(false); | ||
|
||
addClasses(subject, "foo", "bar"); | ||
|
||
expect(subject.classList.contains("foo")).toBe(true); | ||
expect(subject.classList.contains("bar")).toBe(true); | ||
}); | ||
|
||
it("returns `true` if all given classes has been added to element", () => { | ||
useFixture(`<div class="root"></div>`); | ||
|
||
const subject = document.querySelector(".root"); | ||
|
||
expect(subject.classList.contains("foo")).toBe(false); | ||
expect(subject.classList.contains("bar")).toBe(false); | ||
|
||
expect(addClasses(subject, "foo", "bar")).toBe(true); | ||
|
||
expect(subject.classList.contains("foo")).toBe(true); | ||
expect(subject.classList.contains("bar")).toBe(true); | ||
}); | ||
|
||
it("returns `true` if any given class has been added to element", () => { | ||
useFixture(`<div class="root foo"></div>`); | ||
|
||
const subject = document.querySelector(".root"); | ||
|
||
expect(subject.classList.contains("foo")).toBe(true); | ||
expect(subject.classList.contains("bar")).toBe(false); | ||
|
||
expect(addClasses(subject, "foo", "bar")).toBe(true); | ||
|
||
expect(subject.classList.contains("foo")).toBe(true); | ||
expect(subject.classList.contains("bar")).toBe(true); | ||
}); | ||
|
||
it("returns `true` if any given class has been added to element", () => { | ||
useFixture(`<div class="root foo bar"></div>`); | ||
|
||
const subject = document.querySelector(".root"); | ||
|
||
expect(subject.classList.contains("foo")).toBe(true); | ||
expect(subject.classList.contains("bar")).toBe(true); | ||
|
||
expect(addClasses(subject, "foo", "bar")).toBe(false); | ||
|
||
expect(subject.classList.contains("foo")).toBe(true); | ||
expect(subject.classList.contains("bar")).toBe(true); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* @flow */ | ||
|
||
import type { CSSClass } from "./types"; | ||
|
||
import addClass from "./add-class"; | ||
|
||
function addClasses(element: Element, ...cssClasses: Array<CSSClass>) { | ||
return cssClasses.reduce( | ||
(result, cssClass) => addClass(element, cssClass) || result, | ||
false | ||
); | ||
} | ||
|
||
export default addClasses; |
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