Skip to content

Commit

Permalink
Create sandpackContenxt.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
danilowoz committed Apr 29, 2022
1 parent 4ec8830 commit e17ca7c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions sandpack-react/src/contexts/sandpackContenxt.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import { SandpackProvider } from "./sandpackContext";

import { create } from "react-test-renderer";
describe(SandpackProvider, () => {
it("updates a file", () => {
const root = create(<SandpackProvider template="react" />);
const instance = root.getInstance();

expect(instance.state.files["/App.js"]).toEqual({
code: `export default function App() {
return <h1>Hello World</h1>
}
`,
});

instance.updateFile("/App.js", "Foo");

expect(instance.state.files["/App.js"]).toEqual({ code: `Foo` });
});

it("updates multiples files", () => {
const root = create(<SandpackProvider template="react" />);
const instance = root.getInstance();

instance.updateFile({ "/App.js": "Foo", "/index.js": "Baz" });

expect(instance.state.files["/App.js"]).toEqual({ code: `Foo` });
expect(instance.state.files["/index.js"]).toEqual({ code: `Baz` });
});

it("updates multiples files in a row", () => {
const root = create(<SandpackProvider template="react" />);
const instance = root.getInstance();

instance.updateFile("/App.js", "Foo");
instance.updateFile("/index.js", "Baz");

expect(instance.state.files["/App.js"]).toEqual({ code: `Foo` });
expect(instance.state.files["/index.js"]).toEqual({ code: `Baz` });
});
});

0 comments on commit e17ca7c

Please sign in to comment.