Skip to content

Commit

Permalink
Add getText function
Browse files Browse the repository at this point in the history
  • Loading branch information
demiazz committed May 31, 2017
1 parent da71e10 commit 5675782
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/traversing/get-text.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getText } from "../../src";

describe("getText", () => {
afterEach(clearFixtures);

it("returns inner text of element", () => {
useFixture(`
<div class="root">
Parent Text
<div>
Children Text
</div>
</div>
`);

const subject = document.querySelector(".root");

expect(getText(subject)).toEqual(subject.textContent);
});
});
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import setText from "./manipulation/set-text";
import query from "./quering/query";
import queryAll from "./quering/query-all";
import closest from "./traversing/closest";
import getText from "./traversing/get-text";
import matches from "./traversing/matches";
import parent from "./traversing/parent";
import parentBy from "./traversing/parent-by";
Expand Down Expand Up @@ -69,6 +70,7 @@ export {
query,
queryAll,
closest,
getText,
matches,
parent,
parentBy,
Expand Down
7 changes: 7 additions & 0 deletions src/traversing/get-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* @flow */

function getText(element: Element): string {
return element.textContent;
}

export default getText;

0 comments on commit 5675782

Please sign in to comment.