Skip to content

The Core Language

Arthur Guiot edited this page Jan 8, 2018 · 2 revisions

The concept

EyeJS is designed to be as easy to use as possible, which means you'll be able to set it up as fast as possible.

To achieve that, we need a structure that we'll find everywhere in the project.

A typical test file will look like:

//  our code (we recommend using require() for large projects)
function sum(a, b) {
    return a+b;
}
function multiply(a, b) {
    return a*b;
}
// the tests
eye.describe("Math test", () => {
    eye.test("sum", "node",
        $ => $(sum(1,2)).Equal(3),
        $ => $(sum(0.2, 0.4)).isCloseTo(0.6)
    )
    eye.test("multiply", "node",
        $ => $(multiply(3, 6)).Equal(18)
    )
})

eye object

Above, we saw that the eye object had 2 instances, the describe instance and the test instance. The first one will group multiple tests.

It has no truly useful features, but it helps to read your test file.

Then we have the most important one, the test instance. It will always look like:

eye.test(name, type, ...callbacks)

The type will be either "node" or "browser". The first one will execute tests in the main process, whereas the "browser" type will open an HTML file in the browser that contains tests.

Here is an example of a browser based test:

index.html

<h1>Hello World!</h1>
<script src="/eyejs/" charset="utf-8"></script>
<script type="text/javascript">
eye.test( // There is no name for browser tests
	$ => $(document.querySelector("h1").innerHTML).Match(/Hello/),
	$ => $(1+2).Equal(3),
	$ => $(document.querySelector("h1")).visual()
);
eye.checkout(); // What's that? Wait a second, we'll come to that later
</script>

test.js

eye.test("Browser test", "browser", path.join(__testDir, "index.html"))

As you can see, we need to join 2 paths, the __testDir and our html file. The __testDir will represent the folder where the test.js file is executed.

In the HTML file, you see that eye has a new instance: checkout. This instance is unique to browser tests, will submit all the result to the original eye command and close the window.

⚠️ You can only have 1 browser test by $ eye command


⚠️ Questions?

Don't hesitate to ask your questions ⁉️ in the issue part 😁