Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const render = (Component, {target = document.createElement('div'), ...op
target,
})

mountedContainers.add(component)
mountedContainers.add({target, component})
return {
component,
// eslint-disable-next-line no-console
Expand All @@ -20,7 +20,11 @@ export const render = (Component, {target = document.createElement('div'), ...op
}

const cleanupAtContainer = container => {
container.$destroy()
const {target, component} = container
component.$destroy()
if (target.parentNode === document.body) {
document.body.removeChild(target)
}
mountedContainers.delete(container)
}

Expand Down
8 changes: 8 additions & 0 deletions tests/render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ describe('render', () => {
})

test('debug', () => {
const originalConsole = global.console

global.console = {log: jest.fn()}

const {debug} = render(App)

debug()

expect(global.console.log).toHaveBeenCalledWith(prettyDOM(document.body))

global.console = originalConsole
})

test('custom container target', () => {
Expand All @@ -61,4 +65,8 @@ describe('render', () => {
expect(getByText('Hello world!')).toBeInTheDocument()
expect(getByTestId('custom-target')).toBeInTheDocument()
})

test('after each test above, document is clean from targets and components', () => {
expect(document.body.innerHTML).toBe('<div></div>')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output here is dependent on previous tests,

  • before: <div></div><div></div><div></div><div></div><main data-testid=\"custom-target\"></main>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the body will be entirely empty after this great addition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @EmilTholin. It should be empty

Copy link
Contributor Author

@oieduardorabelo oieduardorabelo May 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed is happening, as we can see in the failed build on travis:

i bet it was some kind of local jest cache, running with --no-cache seems to have fixed it!

thanks @EmilTholin @benmonro

})
})