UNPKG

reblend-testing-library

Version:

Simple and complete Reblendjs testing utilities that encourage good testing practices.

95 lines (93 loc) 2.67 kB
"use strict"; var _reblendjs = require("reblendjs"); var _ = require("../"); beforeEach(() => { jest.spyOn(console, 'log').mockImplementation(() => {}); }); afterEach(() => { console.log.mockRestore(); }); test('debug pretty prints the container', async () => { const HelloWorld = class /* @Reblend: Transformed from function to class */ extends _reblendjs.Reblend { static ELEMENT_NAME = "HelloWorld"; constructor() { super(); } async initState() {} async initProps() { this.props = {}; } async html() { return _reblendjs.Reblend.construct.bind(this)("h1", null, "Hello World"); } }; const { debug } = await (0, _.render)(_reblendjs.Reblend.construct.bind(this)(HelloWorld, null)); debug(); expect(console.log).toHaveBeenCalledTimes(1); expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Hello World')); }); test('debug pretty prints multiple containers', async () => { const HelloWorld = class /* @Reblend: Transformed from function to class */ extends _reblendjs.Reblend { static ELEMENT_NAME = "HelloWorld"; constructor() { super(); } async initState() {} async initProps() { this.props = {}; } async html() { return _reblendjs.Reblend.construct.bind(this)(_reblendjs.Reblend, null, _reblendjs.Reblend.construct.bind(this)("h1", { "data-testid": "testId" }, "Hello World"), _reblendjs.Reblend.construct.bind(this)("h1", { "data-testid": "testId" }, "Hello World")); } }; const { debug } = await (0, _.render)(_reblendjs.Reblend.construct.bind(this)(HelloWorld, null)); const multipleElements = _.screen.getAllByTestId('testId'); debug(multipleElements); expect(console.log).toHaveBeenCalledTimes(2); expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Hello World')); }); test('allows same arguments as prettyDOM', async () => { const HelloWorld = class /* @Reblend: Transformed from function to class */ extends _reblendjs.Reblend { static ELEMENT_NAME = "HelloWorld"; constructor() { super(); } async initState() {} async initProps() { this.props = {}; } async html() { return _reblendjs.Reblend.construct.bind(this)("h1", null, "Hello World"); } }; const { debug, container } = await (0, _.render)(_reblendjs.Reblend.construct.bind(this)(HelloWorld, null)); debug(container, 6, { highlight: false }); expect(console.log).toHaveBeenCalledTimes(1); expect(console.log.mock.calls[0][0]).toMatchInlineSnapshot(` "<div> ..." `); }); /* eslint no-console: "off", */