How to use the ava.cb function in ava

To help you get started, we’ve selected a few ava 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 sasha240100 / between.js / test / api.spec.js View on Github external
import './polyfill';
import test from 'ava';
import once from 'once';
import Between from '../src/between';

test.cb('API', t => {
  t.plan(3);

  // TODO: write tests for .duration & extend for value (is correct)
  new Between(1, 10)
    .time(1000)
    .on('update', once(v => {
      t.truthy(v, 'value is passed & "update" was called');
    }))
    .on('complete', (v, {localTime}) => {
      t.is(v, 10);
      t.true(localTime >= 1000, 'localTime is correct');
      t.end();
    });
});
github typicode / hotel / test / daemon / app.js View on Github external
.get('/')
    .expect(200, t.end)
})

//
// Test env variables
//

test.cb('GET / should contain custom env values', t => {
  request(app)
    .get('/')
    .set('Host', `custom-env.${tld}`)
    .expect(200, /FOO_VALUE/, t.end)
})

test.cb('GET / should contain proxy env values', t => {
  request(app)
    .get('/')
    .set('Host', `custom-env.${tld}`)
    .expect(200, /http:\/\/127.0.0.1:2000\/proxy.pac/, t.end)
})

//
// Test headers
//

test.cb('GET node.tld/ should contain X-FORWARD headers', t => {
  request(app)
    .get('/')
    .set('Host', `node.${tld}`)
    .expect(200, new RegExp(`x-forwarded-host: node.${tld}`), t.end)
})
github punchcard-cms / punchcard / tests / server.js View on Github external
.set('cookie', cookie)
      .expect(200)
      .end((err, res) => {
        t.is(err, null, 'Should not have an error');
        t.regex(res.text, /DOCTYPE html/, 'should have an html doctype');

        t.end();
      });
  });
});

//////////////////////////////
// Content Pages - content edit page
//////////////////////////////

test.cb('Invalid Content Type - Content Type Edit Page', t => {
  addService().then(revision => {
    agent
      .get(`/content/foo/${serviceUuid}/${revision}/edit`)
      .set('cookie', cookie)
      .expect(404)
      .end(err => {
        t.is(err, null, 'Should not have an error');
        t.end();
      });
  });
});

test.cb('Non UUID - Content Type Edit Page', t => {
  agent
    .get('/content/services/foo/123/edit')
    .set('cookie', cookie)
github tonickkozlov / vue-tweet-embed / index.spec.jsdom.js View on Github external
t.is(mockTwttr.widgets.createTimeline.args[0].length, 3)
        t.is(mockTwttr.widgets.createTimeline.args[0][0]['screenName'], '123')
        t.is(mockTwttr.widgets.createTimeline.args[0][0]['sourceType'], 'profile')
        t.is(mockTwttr.widgets.createTimeline.args[0][1], vm.$el)
        t.deepEqual(mockTwttr.widgets.createTimeline.args[0][2], { foo: 'bar' })

        // check that the element was indeed injected
        const $loadedTweet = vm.$el.querySelector('#loadedTweet')

        t.is($loadedTweet.id, 'loadedTweet')
        t.is($loadedTweet.innerText, 'tweet text')
        t.end()
    }, 0)
})

test.cb('Should show a newly created Timeline element as list\'s immeditate child', t => {
    const { Timeline, Vue, window, document } = t.context
    const mockTwttr = {
        widgets: {
            createTimeline: spy((userId, parent) => {
                const $mockTweet = document.createElement('div')
                $mockTweet.setAttribute('id', 'loadedTweet')
                $mockTweet.setAttribute('sourceType', 'loadedSouceType')
                $mockTweet.innerText = 'tweet text'
                parent.appendChild($mockTweet)
                return Promise.resolve($mockTweet)
            })
        }
    }

    window.twttr = mockTwttr
github toniov / p-iteration / test / index.js View on Github external
t.is(err.message, 'test');
});

test('forEach using thisArg', async (t) => {
  let total = 0;
  const testObj = { test: 1 };
  await forEach([1, 2, 3], async function (num, index, array) {
    await delay();
    t.is(array[index], num);
    t.deepEqual(this, testObj);
    total += num;
  }, testObj);
  t.is(total, 6);
});

test.cb('forEach used with promises in a non-async function', (t) => {
  let total = 0;
  forEach([1, 2, 3], async function (num, index, array) {
    await delay();
    t.is(array[index], num);
    total += num;
  }).then(() => {
    t.is(total, 6);
    t.end();
  });
});

test('forEach should not execute any callback if array is empty', async (t) => {
  let count = 0;
  await forEach([], async () => {
    await delay();
    count++;
github dashersw / cote / test / pending-balanced-requester.js View on Github external
import test from 'ava';
import LogSuppress from '../lib/log-suppress';
import r from 'randomstring';
import async from 'async';

const environment = r.generate();
const { PendingBalancedRequester, Responder } = require('../')({ environment });

LogSuppress.init(console);

test('Supports environment', (t) => {
    t.is(PendingBalancedRequester.environment, `${environment}:`);
    t.is(Responder.environment, `${environment}:`);
});

test.cb('Supports simple req&res', (t) => {
    t.plan(1);

    const requester = new PendingBalancedRequester({ name: `${t.title}: simple requester` });
    const responder = new Responder({ name: `${t.title}: simple responder` });

    requester.send({ type: 'test', args: [1, 2, 3] });

    responder.on('test', (req) => {
        t.deepEqual(req.args, [1, 2, 3]);
        t.end();
    });
});

test.cb('Supports keys', (t) => {
    const key = r.generate();
github borodean / assets / test / data.js View on Github external
t.end();
  });
});

test.cb('node-style callback w/ options', (t) => {
  resolveData('picture.png', {
    basePath: 'test/fixtures',
    loadPaths: ['fonts', 'images'],
  }, (err, resolvedDataUrl) => {
    t.is(err, null);
    t.is(resolvedDataUrl.slice(0, 32), 'data:image/png;base64,iVBORw0KGg');
    t.end();
  });
});

test.cb('node-style callback + non-existing file', (t) => {
  resolveData('non-existing.gif', (err, resolvedDataUrl) => {
    t.true(err instanceof Error);
    t.is(err.message, 'Asset not found or unreadable: non-existing.gif');
    t.is(resolvedDataUrl, undefined);
    t.end();
  });
});
github thinkjs / think-payload / test / index.js View on Github external
test.cb('should be able to receive both file and text', t => {
  request(app.callback())
  .post('/')
  .attach('xxfile', path.join(__dirname, '../index.js'))
  .field('text', 'test text')
  .expect(200)
  .end((err, res) => {
    if (err) throw err;
    t.is(res.body.post.text, 'test text');
    t.is(res.body.file.xxfile.name, 'index.js');
    t.is(res.body.file.xxfile.type, 'application/javascript');
    t.end();
  });
});

test.cb('should be able to receive xml type requests', t => {
  request(app.callback())
  .post('/')
  .set('Content-Type', 'text/xml')
  .send("Hello Berwin!")
  .expect(200)
  .end((err, res) => {
    if (err) throw err;
    t.is(res.body.post.root, 'Hello Berwin!');
    t.end();
  });
});

test.cb('xml support parameters', t => {
  request(app.callback())
  .post('/')
  .set('Content-Type', 'text/xml')
github jamesramsay / hercule / test / units / inflate-stream.js View on Github external
testStream
    .on('readable', function read() {
      let chunk = null;
      while ((chunk = this.read()) !== null) {
        t.deepEqual(chunk.content, expected);
      }
    })
    .on('error', () => t.fail())
    .on('end', () => t.end());

  testStream.write(input);
  testStream.end();
});


test.cb('should emit error with invalid http link', (t) => {
  const input = {
    content: ':[Example](size.md)',
    link: 'http://github.com/i-dont-exist.md',
    parents: [],
    references: [],
  };
  const testStream = new InflateStream();

  nock('http://github.com').get('/i-dont-exist.md').reply(404);

  t.plan(2);
  testStream
    .on('readable', function read() {
      if (this.read() !== null) t.fail();
    })
    .on('error', (err) => {
github Wenzil / Mhysa / src / index.spec.ts View on Github external
expect(part).to.deep.equal(expectedElements[i]);
                t.pass();
                i++;
            })
            .on("error", t.end)
            .on("end", t.end);

        source.push("abc");
        source.push(0);
        source.push({ a: "a", b: "b", c: "c" });
        source.push(["a", "b", "c"]);
        source.push(null);
    },
);

test.cb(
    "collect() collects streamed elements into an array (object, flowing mode)",
    t => {
        t.plan(1);
        const source = new Readable({ objectMode: true });

        source
            .pipe(collect({ objectMode: true }))
            .on("data", collected => {
                expect(collected).to.deep.equal(["a", "b", "c"]);
                t.pass();
            })
            .on("error", t.end)
            .on("end", t.end);

        source.push("a");
        source.push("b");