From b0ae9a0adae6ee775910c16164e966e8d2e4dc5f Mon Sep 17 00:00:00 2001 From: jiachen Date: Sat, 12 Oct 2019 09:53:44 +0800 Subject: [PATCH 1/2] docs: add riot ecosystem plugin --- docs/ecosystem-riot-testing-library.md | 36 ++++++++++++++++++++++++++ website/sidebars.json | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 docs/ecosystem-riot-testing-library.md diff --git a/docs/ecosystem-riot-testing-library.md b/docs/ecosystem-riot-testing-library.md new file mode 100644 index 000000000..7da686e5b --- /dev/null +++ b/docs/ecosystem-riot-testing-library.md @@ -0,0 +1,36 @@ +--- +id: ecosystem-riot-testing-library +title: riot-testing-library +--- + +[`riot-testing-library`][gh] builds on top of [DOM Testing Library](https://github.com/testing-library/dom-testing-library) by adding APIs for working with [Riot.js](https://riot.js.org/) components. + +``` +npm install --save-dev riot-testing-library +``` + +```javascript +import render, { cleanup, fireEvent } from 'riot-testing-library' +import TestTag from './test.tag' + +afterEach(() => { + cleanup() +}) + +test('should show count text when rendered', () => { + const { queryByTestId } = render(TestTag, {count: 10}); + expect(queryByTestId('count').textContent).toBe("10"); +}) + +test('should add count when click add button text', async () => { + const { queryByTestId } = render(TestTag, {count: 1}); + expect(queryByTestId('count').textContent).toBe("1"); + fireEvent.click(queryByTestId('button')) + expect(queryByTestId('count').textContent).toBe("2"); +}) +``` + + +- [riot-testing-library on GitHub][gh] + +[gh]: https://github.com/ariesjia/riot-testing-library diff --git a/website/sidebars.json b/website/sidebars.json index 7ad2a5e2c..bf0ab83e1 100755 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -110,7 +110,8 @@ "ecosystem-bs-jest-dom", "ecosystem-jest-native", "ecosystem-react-select-event", - "ecosystem-eslint-plugin-testing-library" + "ecosystem-eslint-plugin-testing-library", + "ecosystem-riot-testing-library" ], "Help": ["faq", "learning", "contributing"] }, From 93cf9348adc0d15574df7e8c2614654447b1ee95 Mon Sep 17 00:00:00 2001 From: jiachen Date: Sun, 13 Oct 2019 01:25:19 +0800 Subject: [PATCH 2/2] docs: remove unnecessary async & add auto cleanup --- docs/ecosystem-riot-testing-library.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/ecosystem-riot-testing-library.md b/docs/ecosystem-riot-testing-library.md index 7da686e5b..e633a5b0e 100644 --- a/docs/ecosystem-riot-testing-library.md +++ b/docs/ecosystem-riot-testing-library.md @@ -10,19 +10,15 @@ npm install --save-dev riot-testing-library ``` ```javascript -import render, { cleanup, fireEvent } from 'riot-testing-library' +import render, { fireEvent } from 'riot-testing-library' import TestTag from './test.tag' -afterEach(() => { - cleanup() -}) - test('should show count text when rendered', () => { const { queryByTestId } = render(TestTag, {count: 10}); expect(queryByTestId('count').textContent).toBe("10"); }) -test('should add count when click add button text', async () => { +test('should add count when click add button text', () => { const { queryByTestId } = render(TestTag, {count: 1}); expect(queryByTestId('count').textContent).toBe("1"); fireEvent.click(queryByTestId('button'))