Files
firefox/devtools/client/webconsole/test/node/components/message-container.test.js
T
Nicolas Chevobbe a23e6858b0 Bug 1572008 - Re-organize WebConsole client tests folder. r=Honza.
- mochitest folder is renamed browser.
- unit folder is rename xpcshell.
- all the file and folder for mocha are put in a node folder.

We take this as an opportunity to revist our stub-generating
mochitests.
Previously we had 2 tests for each kind of stubs, one for check,
the other one for updating.
It was not ideal when you wanted to update all the stubs at once
because you add either to mention every 5 files, or unskip the
update test files.
We now merge the update and the check files in a single test.
By default, the test that the stubs are up to date, and if you
pass the --setenv WEBCONSOLE_STUBS_UPDATE=true param, it will
update the stubs.
This allow us to move the function that actually generate the stub
in the test file, and have a helper file for multi-purpose functions.
Because these tests are failing on TRY, let's disabled them so we
can land the test re-organization (we'll re-enable them in Bug 1572667).

Differential Revision: https://phabricator.services.mozilla.com/D41344
2019-08-09 09:54:41 +00:00

69 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test utils.
const expect = require("expect");
const { render } = require("enzyme");
const { createFactory } = require("devtools/client/shared/vendor/react");
// Components under test.
let {
MessageContainer,
getMessageComponent,
} = require("devtools/client/webconsole/components/Output/MessageContainer");
MessageContainer = createFactory(MessageContainer);
const ConsoleApiCall = require("devtools/client/webconsole/components/Output/message-types/ConsoleApiCall");
const CSSWarning = require("devtools/client/webconsole/components/Output/message-types/CSSWarning");
const EvaluationResult = require("devtools/client/webconsole/components/Output/message-types/EvaluationResult");
const PageError = require("devtools/client/webconsole/components/Output/message-types/PageError");
// Test fakes.
const {
stubPreparedMessages,
} = require("devtools/client/webconsole/test/node/fixtures/stubs/index");
const serviceContainer = require("devtools/client/webconsole/test/node/fixtures/serviceContainer");
describe("MessageContainer component:", () => {
it("pipes data to children as expected", () => {
const message = stubPreparedMessages.get("console.log('foobar', 'test')");
const rendered = render(
MessageContainer({
getMessage: () => message,
serviceContainer,
})
);
expect(rendered.text().includes("foobar")).toBe(true);
});
it("picks correct child component", () => {
const messageTypes = [
{
component: ConsoleApiCall,
message: stubPreparedMessages.get("console.log('foobar', 'test')"),
},
{
component: EvaluationResult,
message: stubPreparedMessages.get("new Date(0)"),
},
{
component: PageError,
message: stubPreparedMessages.get(
"ReferenceError: asdf is not defined"
),
},
{
component: CSSWarning,
message: stubPreparedMessages.get(
"Unknown property ‘such-unknown-property’. Declaration dropped."
),
},
];
messageTypes.forEach(info => {
const { component, message } = info;
expect(getMessageComponent(message)).toBe(component);
});
});
});