diff --git a/spec/traversing/get-text.spec.js b/spec/traversing/get-text.spec.js new file mode 100644 index 0000000..f744035 --- /dev/null +++ b/spec/traversing/get-text.spec.js @@ -0,0 +1,20 @@ +import { getText } from "../../src"; + +describe("getText", () => { + afterEach(clearFixtures); + + it("returns inner text of element", () => { + useFixture(` +
+ Parent Text +
+ Children Text +
+
+ `); + + const subject = document.querySelector(".root"); + + expect(getText(subject)).toEqual(subject.textContent); + }); +}); diff --git a/src/index.js b/src/index.js index 917ae1f..31c9ec0 100644 --- a/src/index.js +++ b/src/index.js @@ -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"; @@ -69,6 +70,7 @@ export { query, queryAll, closest, + getText, matches, parent, parentBy, diff --git a/src/traversing/get-text.js b/src/traversing/get-text.js new file mode 100644 index 0000000..828fc7b --- /dev/null +++ b/src/traversing/get-text.js @@ -0,0 +1,7 @@ +/* @flow */ + +function getText(element: Element): string { + return element.textContent; +} + +export default getText;