Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tape: how to replace t.test and t.skip #89

Closed
Haroenv opened this issue Oct 25, 2017 · 5 comments
Closed

Tape: how to replace t.test and t.skip #89

Haroenv opened this issue Oct 25, 2017 · 5 comments

Comments

@Haroenv
Copy link
Contributor

Haroenv commented Oct 25, 2017

Our codebase has quite a few of those, but now that's the only warning left, except sinon ( #68 )

An example test with those looks like:

'use strict';

var algoliasearchHelper = require('../../../index');

var _ = require('lodash');

var fakeClient = {
  addAlgoliaAgent: function() {}
};

test('helper.hasRefinements(attribute)', function() {
  var helper;

  // cannot be tested since there's no way to know that a numeric refinement
  // was once added then removed thus we always return false when not found
  t.skip('undefined attribute', function(tt) {
    setup();
    tt.throws(_.partial(helper.hasRefinements, 'unknown'), Error, 'it throws when unknown attribute');
    tt.end();
  });

  t.test('numericRefinement', function(tt) {
    tt.test('with refinement', function(ttt) {
      setup();
      helper.addNumericRefinement('price', '=', 1337);
      ttt.equal(helper.hasRefinements('price'), true);
      ttt.end();
    });

    tt.test('without refinement', function(ttt) {
      setup();
      helper.addNumericRefinement('price', '=', 1337);
      helper.clearRefinements('price');
      ttt.equal(helper.hasRefinements('price'), false);
      ttt.end();
    });
  });

  t.test('facet', function(tt) {
    tt.test('with refinement', function(ttt) {
      setup({
        facets: ['color']
      });
      helper.toggleFacetRefinement('color', 'red');
      ttt.equal(helper.hasRefinements('color'), true);
      ttt.end();
    });

    tt.test('without refinement', function(ttt) {
      setup({
        facets: ['color']
      });
      ttt.equal(helper.hasRefinements('color'), false);
      ttt.end();
    });
  });

  t.test('disjunctiveFacet', function(tt) {
    tt.test('with refinement', function(ttt) {
      setup({
        disjunctiveFacets: ['author']
      });
      helper.toggleFacetRefinement('author', 'John Spartan');
      ttt.equal(helper.hasRefinements('author'), true);
      ttt.end();
    });

    tt.test('without refinement', function(ttt) {
      setup({
        disjunctiveFacets: ['author']
      });
      ttt.equal(helper.hasRefinements('author'), false);
      ttt.end();
    });
  });

  t.test('hierarchicalFacet', function(tt) {
    tt.test('with refinement', function(ttt) {
      setup({
        hierarchicalFacets: [{
          name: 'category',
          attributes: ['category.lvl0', 'category.lvl1']
        }]
      });
      helper.toggleFacetRefinement('category', 'Action Movies > Max');
      ttt.equal(helper.hasRefinements('category'), true);
      ttt.end();
    });

    tt.test('without refinement', function(ttt) {
      setup({
        hierarchicalFacets: [{
          name: 'category',
          attributes: ['category.lvl0', 'category.lvl1']
        }]
      });
      ttt.equal(helper.hasRefinements('category'), false);
      ttt.end();
    });
  });

  function setup(params) {
    helper = algoliasearchHelper(fakeClient, 'index', params);
  }
});
@Haroenv
Copy link
Contributor Author

Haroenv commented Oct 25, 2017

t.test can be replaced by describe the outer test, and test the inner one, but I'm not sure how many levels deep that can go. Seems to be infinite with tape.

t.skip can be replaced by describe.skip

@skovhus
Copy link
Owner

skovhus commented Oct 25, 2017

So the test here is a bit funky. It doesn't really follow Tape documentation.

IMO

test('helper.hasRefinements(attribute)', function() {
  t.skip('undefined attribute', function(tt) {

should be

test('helper.hasRefinements(attribute)', function(t) {
  t.skip('undefined attribute', function() {

So if you get rid of all the ttt and tt and just use the t coming from test(... then the conversion should be fine.

@Haroenv
Copy link
Contributor Author

Haroenv commented Oct 25, 2017

Oh that would help too! I’ll do that change then, didn’t happen in many cases AFAICT

@skovhus
Copy link
Owner

skovhus commented Oct 29, 2017

Did it work? : )

@Haroenv
Copy link
Contributor Author

Haroenv commented Oct 30, 2017

We aren't moving to Jest right now yet, so I didn't spend to much effort on those tests. Will reopen if we need more help after moving to a more standard way of writing those tests

@Haroenv Haroenv closed this as completed Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants