test CodeBlock

This commit is contained in:
2019-04-20 22:19:37 +03:00
parent 033e6696b4
commit bacb7bf2b2
2 changed files with 28 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
/* tslint:disable: blueprint-html-components */
import hljs from "highlight.js";
import * as hljs from "highlight.js";
import * as React from "react";
import "./CodeBlock.scss";

View File

@@ -0,0 +1,27 @@
import { mount } from "enzyme";
import * as React from "react";
import * as hljs from "highlight.js";
import { CodeBlock } from "../CodeBlock";
const highlightSpy = jest.spyOn(hljs, "highlightBlock");
afterEach(() => {
jest.restoreAllMocks();
});
describe("<CodeBlock />", () => {
it("should render code and highlight it when updated", () => {
const text1 = `console.log("Hello")`;
const text2 = `console.log("world")`;
const wrapper = mount(<CodeBlock value={text1} language="js" />);
expect(wrapper.find("pre")).toHaveLength(1);
expect(wrapper.text()).toBe(text1);
expect(highlightSpy).toHaveBeenCalledTimes(1);
wrapper.setProps({ value: text2, language: "js" });
expect(wrapper.text()).toBe(text2);
expect(highlightSpy).toHaveBeenCalledTimes(2);
});
});