samedi 5 janvier 2019

Getting Mobx Observables into test file

I'm writing tests for my application, i need to get my mobx observable from another file into the test so that i can check if the value is what i expect.

I'm using pupeteer to mimic the users behaviour, so lets say i mimic typing an input, then i would like to check if the input value observable contains the proper value.

Sample of my test:

import puppeteer from "puppeteer";
import expectPuppet from 'expect-puppeteer'
import {inject, observer} from "mobx-react";

let page;
let browser;

beforeAll(async () => {
    browser = await puppeteer.launch({ headless: false, slowMo: 250, defaultViewport: {width: 1920, height: 1080}})
    page = await browser.newPage();

    await page.goto("localhost:3001");
}, 16000000)

it('Browse Auctions Input', async () => {
    await page.waitForSelector('input.auctionSearchInput')
    expect(<myObservable>).toBe(''); //* Check initial input in observable

    const searchInput = await page.$('input.auctionSearchInput');
    const input = ['s','h','o','e', 's'];
    let expectedInput = ''

    for (let i = 0; i < input.length; i++) {
        await searchInput.type(input[i], 4000);
        expectedInput += input[i];
        expect(<myObservable>).toBe(expectedInput)
    }
}, 1600000)

Tried importing the observables: - import {myObservable} from './pathtofile' but it ends up being undefined when i read it.

Aucun commentaire:

Enregistrer un commentaire