Giter Site home page Giter Site logo

bs-enzyme's Introduction

bs-enzyme - BuckleScript bindings for Enzyme npm (scoped)

๐Ÿšง Note: This package is still very experimental. Expect frequent, breaking changes right up until 1.0 is released. ๐Ÿšง


Status

  • Most of the shallow API is implemented
  • The simulate method is currently wrapped in multiple simulateN functions to handle mixed variadic arguments
  • Neither the render nor mount APIs are implemented
  • I haven't extensively tested most of the functions, so some might be broken

Example

Using the excellent bs-jest

open Jest;

let setup ::title="Test" ::handleClick=(fun _evt => ()) () =>
  Enzyme.shallow <DummyComponent title handleClick />;

let header wrapper =>
  wrapper
  |> Enzyme.find "#header"
  |> Enzyme.first;

let listItems wrapper =>
  wrapper
  |> Enzyme.find "#list"
  |> Enzyme.children;

describe "DummyComponent" (fun () => {
  open Expect;

  test "renders a #header" (fun () => {
    let title = "A test title";
    let wrapper = setup title::title ();
    let headerNodes = wrapper |> header;

    expect (Enzyme.length headerNodes) |> toBe 1;
  });

  test "has the expected h1 tag in the #header" (fun () => {
    let title = "A test title";
    let wrapper = setup title::title ();
    let expectedNode = <h1>(ReasonReact.stringToElement title)</h1>;

    expect (Enzyme.contains expectedNode wrapper) |> toBe true;
  });

  test "initially has its `clicked` state set to false" (fun () => {
    let wrapper = setup ();
    let { clicked }: DummyComponent.state = Enzyme.state wrapper;
    expect clicked |> toBe false;
  });

  test "folds left properly" (fun () => {
    let items = setup () |> listItems;
    let result =  Enzyme.foldLeft (fun text node => text ^ Enzyme.text node) "" items;
    expect result |> toBe "OneTwoThree";
  });
});

See more examples in the project's tests directory.

Installation

$ npm install --save-dev bs-enzyme

Then add bs-enzyme to bs-dev-dependencies in your bsconfig.json:

{
  ...
  "bs-dev-dependencies": ["bs-enzyme"]
}

Note: If you're using this package with bs-jest, be sure to list bs-enzyme first in your dependencies.

bs-enzyme's People

Contributors

rhysforyou avatar viebel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.