How to use the tst.browser function in tst

To help you get started, we’ve selected a few tst examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unihooks / unihooks / test / useQueryParam.js View on Github external
t.deepEqual(log, [1])

  window.history.pushState(null, "useQueryParam", "?x=2");
  await frame()
  t.deepEqual(log, [1, 2])

  window.history.pushState(null, "useQueryParam", "?x=3");
  await frame(3)
  t.deepEqual(log, [1, 2, 3])

  f.unhook()
  clearSearch()
  t.end()
})

t.browser('useQueryParam: default array', async t => {
  let f = enhook(() => {
    let [arr, setArr] = useQueryParam('arr', [])
    t.deepEqual(arr, [])
  })
  f()

  await frame(2)
  f.unhook()
  clearSearch()
  t.end()
})

function clearSearch() {
  window.history.pushState(null, '', window.location.href.split('?')[0])
}
github unihooks / unihooks / test / useQueryParam.js View on Github external
"arr3": [["a", "1"], ["b", "2"], ["c", "3"]],
    "arr4": [{ "a": "1" }, { "b": "2" }, { "c": "3" }],
    "bool": "false",
    "date": "2019-11-17T00:00:00.000Z",
    "num": "-123",
    "obj": { "a": "1", "b": "2", "c": "3", "foo": "bar" },
    "str": "foo"
  })

  await frame(3)
  f.unhook()
  clearSearch()
  t.end()
})

t.browser('useQueryParam: defaults', async t => {
  let log = []

  clearSearch()
  await time(10)

  let f = enhook(() => {
    let [str, setStr] = useQueryParam('str', 'foo')
    let [num, setNum] = useQueryParam('num', -123)
    let [bool, setBool] = useQueryParam('bool', false)
    let [arr1, setArr1] = useQueryParam('arr1', [1, 2, 3])
    let [arr2, setArr2] = useQueryParam('arr2', ['a', 'b', 'c'])
    let [arr3, setArr3] = useQueryParam('arr3', [['a', 1], ['b', 2], ['c', 3]])
    let [arr4, setArr4] = useQueryParam('arr4', [{ a: 1 }, { b: 2 }, { c: 3 }])
    let [obj, setObj] = useQueryParam('obj', { a: 1, b: 2, c: 3, foo: 'bar' })
    let [date, setDate] = useQueryParam('date', new Date('2019-11-17'))
github unihooks / unihooks / test / useQueryParam.js View on Github external
import t from 'tst'
import { useQueryParam, useState, useEffect } from '../src/index'
import enhook from './enhook.js'
import qs from 'qs'
import { tick, idle, frame, time } from 'wait-please'

t.browser('useQueryParam: read values properly', async t => {
  clearSearch()
  let log = []

  let str = qs.stringify({
    str: 'foo',
    num: -123,
    bool: false,
    nul: null,
    undef: undefined,
    arr1: [1, 2, 3],
    arr2: ['a', 'b', 'c'],
    arr3: [['a', 1], ['b', 2], ['c', 3]],
    arr4: [{ a: 1 }, { b: 2 }, { c: 3 }],
    obj: { a: 1, b: 2, c: 3, foo: 'bar' },
    date: new Date('2019-11-17')
  }, { encode: false })
github unihooks / unihooks / test / useQueryParam.js View on Github external
undefined,
    [1, 2, 3],
    ['a', 'b', 'c'],
    [['a', 1], ['b', 2], ['c', 3]],
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    { a: 1, b: 2, c: 3, foo: 'bar' },
    +new Date('2019-11-17T00:00:00.000Z')
  ])

  await frame(2)
  f.unhook()
  clearSearch()
  t.end()
})

t.browser('useQueryParam: write values', async t => {
  clearSearch()

  let f = enhook((params) => {
    let [str, setStr] = useQueryParam('str')
    let [num, setNum] = useQueryParam('num')
    let [bool, setBool] = useQueryParam('bool')
    let [arr1, setArr1] = useQueryParam('arr1')
    let [arr2, setArr2] = useQueryParam('arr2')
    let [arr3, setArr3] = useQueryParam('arr3')
    let [arr4, setArr4] = useQueryParam('arr4')
    let [obj, setObj] = useQueryParam('obj')
    let [date, setDate] = useQueryParam('date')

    setStr(params.str)
    setNum(params.num)
    setBool(params.bool)
github unihooks / unihooks / test / useQueryParam.js View on Github external
"date": "2019-11-17T00:00:00.000Z",
    "num": "-123",
    "obj": { "a": "1", "b": "2", "c": "3", "foo": "bar" },
    "str": "foo"
  })


  f.unhook()
  await time(100)
  clearSearch()
  t.end()
})

t('useQueryParam: custom toString method')

t.browser('useQueryParam: observe updates', async t => {
  clearSearch()
  let log = []
  let f = enhook(() => {
    let [v, setV] = useQueryParam('x', 1)
    log.push(v)
  })
  f()
  await frame(2)
  t.deepEqual(log, [1])

  window.history.pushState(null, "useQueryParam", "?x=2");
  await frame()
  t.deepEqual(log, [1, 2])

  window.history.pushState(null, "useQueryParam", "?x=3");
  await frame(3)

tst

Tests without efforts

MIT
Latest version published 4 months ago

Package Health Score

60 / 100
Full package analysis