<commit_before>
process.env.NODE_ENV = 'test';

var assert = require('assert');
var connect = require('connect');
var request = require('supertest');
var session = require('..');

describe('Cookie Session', function(){
  var cookie;

  describe('when options.signed = true', function(){
    describe('when app.keys are set', function(){
      it('should work', function(done){
        var app = connect();
        app.use(session({
          keys: ['a', 'b']
        }));
        app.use(function (req, res, next) {
          req.session.message = 'hi';
          res.end();
        })

        request(app.listen())
        .get('/')
        .expect(200, done);
      })
    })

    describe('when app.keys are not set', function(){
      it('should throw', function(){
        assert.throws(function () {
          session();
        });
      })
    })
  })

  describe('when options.signed = false', function(){
    describe('when app.keys are not set', function(){
      it('should work', function(done){
        var app = connect();
        app.use(session({
          signed: false
        }));
        app.use(function (req, res, next) {
          req.session.message = 'hi';
          res.end();
        })

        request(app.listen())
        .get('/')
        .expect(200, done);
      })
    })
  })

  describe('when the session contains a ;', function(){
    it('should still work', function(done){
      var app = App();
      app.use(function (req, res, next) {
        if (req.method === 'POST') {
          req.session.string = ';';
          res.statusCode = 204;
          res.end();
        } else {
          res.end(req.session.string);
        }
      })

      var server = app.listen();
      request(server)
      .post('/')
      .expect(204, function(err, res){
        if (err) return done(err);
        var cookie = res.headers['set-cookie'];
        request(server)
        .get('/')
        .set('Cookie', cookie.join(';'))
        .expect(';', done);
      })
    })
  })

  describe('new session', function(){
    describe('when not accessed', function(){
      it('should not Set-Cookie', function(done) {
        var app = App();
        app.use(function (req, res, next) {
          res.end('greetings');
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when accessed and not populated', function(done){
      it('should not Set-Cookie', function(done) {
        var app = App();
        app.use(function (req, res, next) {
          req.session;
          res.end('greetings');
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when populated', function(done){
      it('should Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session.message = 'hello';
          res.end();
        })

        request(app.listen())
        .get('/')
        .expect('Set-Cookie', /express:sess/)
        .expect(200, function(err, res){
          if (err) return done(err);
          cookie = res.header['set-cookie'].join(';');
          done();
        })
      })

      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          res.end(JSON.stringify(this.session));
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })
  })

  describe('saved session', function(){
    describe('when not accessed', function(){
      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          res.end('aklsjdfklasjdf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when accessed but not changed', function(){
      it('should be the same session', function(done){
        var app = App();
        app.use(function (req, res, next) {
          assert.equal(req.session.message, 'hello');
          res.end('aklsjdfkljasdf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect(200, done);
      })

      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          assert.equal(req.session.message, 'hello');
          res.end('aklsjdfkljasdf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when accessed and changed', function(){
      it('should Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session.money = '$$$';
          res.end('klajsdlkfjadsf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect('Set-Cookie', /express:sess/)
        .expect(200, done);
      })
    })
  })

  describe('when session = ', function(){
    describe('null', function(){
      it('should expire the session', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = null;
          res.end('lkajsdf');
        })

        request(app.listen())
        .get('/')
        .expect('Set-Cookie', /express:sess/)
        .expect(200, done);
      })
    })

    describe('{}', function(){
      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = {};
          res.end('lkajsdlkfjasdf');
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        });
      })
    })

    describe('{a: b}', function(){
      it('should create a session', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = { message: 'hello' };
          res.end('klajsdfasdf');
        })

        request(app.listen())
        .get('/')
        .expect('Set-Cookie', /express:sess/)
        .expect(200, done);
      })
    })

    describe('anything else', function(){
      it('should throw', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = 'aklsdjfasdf';
        })

        request(app.listen())
        .get('/')
        .expect(500, done);
      })
    })
  })
})

function App(options) {
  options = options || {};
  options.keys = ['a', 'b'];
  var app = connect();
  app.use(session(options));
  return app;
}
<commit_msg>tests: add req.session.populated tests<commit_after>
process.env.NODE_ENV = 'test';

var assert = require('assert');
var connect = require('connect');
var request = require('supertest');
var session = require('..');

describe('Cookie Session', function(){
  var cookie;

  describe('when options.signed = true', function(){
    describe('when app.keys are set', function(){
      it('should work', function(done){
        var app = connect();
        app.use(session({
          keys: ['a', 'b']
        }));
        app.use(function (req, res, next) {
          req.session.message = 'hi';
          res.end();
        })

        request(app.listen())
        .get('/')
        .expect(200, done);
      })
    })

    describe('when app.keys are not set', function(){
      it('should throw', function(){
        assert.throws(function () {
          session();
        });
      })
    })
  })

  describe('when options.signed = false', function(){
    describe('when app.keys are not set', function(){
      it('should work', function(done){
        var app = connect();
        app.use(session({
          signed: false
        }));
        app.use(function (req, res, next) {
          req.session.message = 'hi';
          res.end();
        })

        request(app.listen())
        .get('/')
        .expect(200, done);
      })
    })
  })

  describe('when the session contains a ;', function(){
    it('should still work', function(done){
      var app = App();
      app.use(function (req, res, next) {
        if (req.method === 'POST') {
          req.session.string = ';';
          res.statusCode = 204;
          res.end();
        } else {
          res.end(req.session.string);
        }
      })

      var server = app.listen();
      request(server)
      .post('/')
      .expect(204, function(err, res){
        if (err) return done(err);
        var cookie = res.headers['set-cookie'];
        request(server)
        .get('/')
        .set('Cookie', cookie.join(';'))
        .expect(';', done);
      })
    })
  })

  describe('new session', function(){
    describe('when not accessed', function(){
      it('should not Set-Cookie', function(done) {
        var app = App();
        app.use(function (req, res, next) {
          res.end('greetings');
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when accessed and not populated', function(done){
      it('should not Set-Cookie', function(done) {
        var app = App();
        app.use(function (req, res, next) {
          req.session;
          res.end('greetings');
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when populated', function(done){
      it('should Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session.message = 'hello';
          res.end();
        })

        request(app.listen())
        .get('/')
        .expect('Set-Cookie', /express:sess/)
        .expect(200, function(err, res){
          if (err) return done(err);
          cookie = res.header['set-cookie'].join(';');
          done();
        })
      })

      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          res.end(JSON.stringify(this.session));
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })
  })

  describe('saved session', function(){
    describe('when not accessed', function(){
      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          res.end('aklsjdfklasjdf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when accessed but not changed', function(){
      it('should be the same session', function(done){
        var app = App();
        app.use(function (req, res, next) {
          assert.equal(req.session.message, 'hello');
          res.end('aklsjdfkljasdf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect(200, done);
      })

      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          assert.equal(req.session.message, 'hello');
          res.end('aklsjdfkljasdf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        })
      })
    })

    describe('when accessed and changed', function(){
      it('should Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session.money = '$$$';
          res.end('klajsdlkfjadsf');
        })

        request(app.listen())
        .get('/')
        .set('Cookie', cookie)
        .expect('Set-Cookie', /express:sess/)
        .expect(200, done);
      })
    })
  })

  describe('when session = ', function(){
    describe('null', function(){
      it('should expire the session', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = null;
          res.end('lkajsdf');
        })

        request(app.listen())
        .get('/')
        .expect('Set-Cookie', /express:sess/)
        .expect(200, done);
      })
    })

    describe('{}', function(){
      it('should not Set-Cookie', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = {};
          res.end('lkajsdlkfjasdf');
        })

        request(app.listen())
        .get('/')
        .expect(200, function(err, res){
          if (err) return done(err);
          assert.strictEqual(res.header['set-cookie'], undefined);
          done();
        });
      })
    })

    describe('{a: b}', function(){
      it('should create a session', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = { message: 'hello' };
          res.end('klajsdfasdf');
        })

        request(app.listen())
        .get('/')
        .expect('Set-Cookie', /express:sess/)
        .expect(200, done);
      })
    })

    describe('anything else', function(){
      it('should throw', function(done){
        var app = App();
        app.use(function (req, res, next) {
          req.session = 'aklsdjfasdf';
        })

        request(app.listen())
        .get('/')
        .expect(500, done);
      })
    })
  })

  describe('req.session', function () {
    describe('.populated', function () {
      it('should be false on new session', function (done) {
        var app = App();
        app.use(function (req, res, next) {
          res.end(String(req.session.populated))
        })

        request(app.listen())
        .get('/')
        .expect(200, 'false', done)
      })

      it('should be true after adding property', function (done) {
        var app = App();
        app.use(function (req, res, next) {
          req.session.message = 'hello!'
          res.end(String(req.session.populated))
        })

        request(app.listen())
        .get('/')
        .expect(200, 'true', done)
      })
    })
  })
})

function App(options) {
  options = options || {};
  options.keys = ['a', 'b'];
  var app = connect();
  app.use(session(options));
  return app;
}
<|endoftext|>


<commit_before>export class MdToastService {
  removeAll() {
    Materialize.Toast.removeAll();
  }

  show(message, displayLength, className?) {
    return new Promise((resolve, reject) => {
      Materialize.toast(message, displayLength, className, () => {
        resolve();
      });
    });
  }
}
<commit_msg>feat(md-toast-service): show returns an instance of Toast This instance can be used to call the new remove method<commit_after>export class MdToastService {
  removeAll() {
    Materialize.Toast.removeAll();
  }

  show(message, displayLength, className?) {
    return new Promise((resolve, reject) => {
      const toastInstance = Materialize.toast(message, displayLength, className, () => {
        resolve(toastInstance);
      });
    });
  }
}
<|endoftext|>


<commit_before>import test from 'ava';
import React from 'react';
import {renderToStaticMarkup as render} from 'react-dom/server';

import Mark from '../src/index';

test('happy case', t => {
    const result = render(*bold*);
    const expected = '
bold
';
    t.is(result, expected);
});

test('readme simple example', t => {
    const str = '*bold* _emphasis_ ~strike~ `code` ```code block```';
    const result = render({str});
    const expected =
        '
bold ' +
        'emphasis ' +
        'strike ' +
        'code ' +
        '
code block

';
    t.is(result, expected);
});

test('readme custom options example', t => {
    const str = '*bold* _underline_ ~strike~ `code`';
    const options = {
        '*': {renderer: 'b'},
        '_': {renderer: 'u'},
        '~': {renderer: ({children}) => {children}},
        '`': {renderer: 'kbd'},
    };
    const result = render({str});
    const expected =
        '
bold ' +
        'underline ' +
        'strike ' +
        'code
';
    t.is(result, expected);
});

test('readme custom wrapper example', t => {
    const result = render(*text*);
    const expected = 'text';
    t.is(result, expected);
});

test('readme rest of props example', t => {
    const result = render(*text*);
    const expected = '
text
';
    t.is(result, expected);
});

test('unclosed element', t => {
    const str = '*bold _under* line_';
    const result = render({str});
    const expected = '
bold _under line_
';
    t.is(result, expected);
});

test('markup inside code tags is ignored', t => {
    const str = '`this _is_ *code*`';
    const result = render({str});
    const expected =
        '
this _is_ *code*
';
    t.is(result, expected);
});

test('markup inside code tags is ignored', t => {
    const str = '`this _is_ *code*`';
    const result = render({str});
    const expected =
        '
this _is_ *code*
';
    t.is(result, expected);
});

test('do not allow multiline styling', t => {
    const str = '*foo\nbar*';
    const result = render({str});
    const expected =
        '
*foo\nbar*
';
    t.is(result, expected);
});

test('nested children', t => {
    const options = {
        '_': {renderer: 'u'},
        '~': {renderer: 'del'},
        '*': {renderer: 'strong'},
        '`': {renderer: 'code'},
    };
    const children = (

            *bold*

                _emphasis_
                `code`
                {null}

            {['~strike~', null, undefined, '', 0, 123]}

    );
    const result = render({children});
    const expected =
        '
' +
            '' +
                'bold' +
                '' +
                    'emphasis' +
                    'code' +
                '' +
                'strike0123' +
            '' +
        '
';
    t.is(result, expected);
});

test('no children', t => {
    const result = render();
    const expected = '';
    t.is(result, expected);
});

test('multichar marks', t => {
    const options = {
        '`': {renderer: 'code'},
        '*': {renderer: 'i'},
        '**': {renderer: 'b'},
        '```': {renderer: 'pre', raw: true},
    };
    const str = '**bold** `code` *italic* ```code block```';
    const result = render(<Mark options={options}>{str}</Mark>);
    const expected =
        '<div>' +
            '<b>bold</b> ' +
            '<code>code</code> ' +
            '<i>italic</i> ' +
            '<pre>code block</pre>' +
        '</div>';
    t.is(result, expected);
});

test('corner case joining code marks', t => {
    const str = '````wat?````';
    const result = render(<Mark>{str}</Mark>);
    const expected =
        '<div>' +
            '<pre>`wat?</pre>`' +
        '</div>';
    t.is(result, expected);
});

test('corner case combining style marks', t => {
    const options = {
        '*': {renderer: 'i'},
        '**': {renderer: 'b'},
    };
    const str = '***wat?***';
    const result = render(<Mark options={options}>{str}</Mark>);
    const expected =
        '<div>' +
            '<b>*wat?</b>*' +
        '</div>';
    t.is(result, expected);
});
<commit_msg>update test<commit_after>import test from 'ava';
import React from 'react';
import {renderToStaticMarkup as render} from 'react-dom/server';

import Mark from '../src/index';

test('happy case', t => {
    const result = render(<Mark options={{'*': {renderer: 'b'}}}>*bold*</Mark>);
    const expected = '<div><b>bold</b></div>';
    t.is(result, expected);
});

test('readme simple example', t => {
    const str = '*bold* _emphasis_ ~strike~ `code` ```code block```';
    const result = render(<Mark>{str}</Mark>);
    const expected =
        '<div><strong>bold</strong> ' +
        '<em>emphasis</em> ' +
        '<del>strike</del> ' +
        '<code>code</code> ' +
        '<pre>code block</pre></div>';
    t.is(result, expected);
});

test('readme custom options example', t => {
    const options = {
        '**': {renderer: 'b'},
        '_': {renderer: 'u'},
        '~': {renderer: ({children}) => <span style={{color: 'red'}}>{children}</span>},
        '`': {renderer: 'kbd'},
    };
    const str = '**bold** _underline_ ~strike~ `code`';
    const result = render(<Mark options={options}>{str}</Mark>);
    const expected =
        '<div><b>bold</b> ' +
        '<u>underline</u> ' +
        '<span style="color:red;">strike</span> ' +
        '<kbd>code</kbd></div>';
    t.is(result, expected);
});

test('readme custom wrapper example', t => {
    const result = render(<Mark wrap='span'>*text*</Mark>);
    const expected = '<span><strong>text</strong></span>';
    t.is(result, expected);
});

test('readme rest of props example', t => {
    const result = render(<Mark className="my-class" style={{background: '#ddd'}}>*text*</Mark>);
    const expected = '<div class="my-class" style="background:#ddd;"><strong>text</strong></div>';
    t.is(result, expected);
});

test('unclosed element', t => {
    const str = '*bold _under* line_';
    const result = render(<Mark>{str}</Mark>);
    const expected = '<div><strong>bold _under</strong> line_</div>';
    t.is(result, expected);
});

test('markup inside code tags is ignored', t => {
    const str = '`this _is_ *code*`';
    const result = render(<Mark>{str}</Mark>);
    const expected =
        '<div><code>this _is_ *code*</code></div>';
    t.is(result, expected);
});

test('markup inside code tags is ignored', t => {
    const str = '`this _is_ *code*`';
    const result = render(<Mark>{str}</Mark>);
    const expected =
        '<div><code>this _is_ *code*</code></div>';
    t.is(result, expected);
});

test('do not allow multiline styling', t => {
    const str = '*foo\nbar*';
    const result = render(<Mark>{str}</Mark>);
    const expected =
        '<div>*foo\nbar*</div>';
    t.is(result, expected);
});

test('nested children', t => {
    const options = {
        '_': {renderer: 'u'},
        '~': {renderer: 'del'},
        '*': {renderer: 'strong'},
        '`': {renderer: 'code'},
    };
    const children = (
        <span>
            *bold*
            <span style={{color: 'red'}}>
                _emphasis_
                <b>`code`</b>
                {null}
            </span>
            {['~strike~', null, undefined, '', 0, 123]}
        </span>
    );
    const result = render(<Mark options={options}>{children}</Mark>);
    const expected =
        '<div>' +
            '<span>' +
                '<strong>bold</strong>' +
                '<span style="color:red;">' +
                    '<u>emphasis</u>' +
                    '<b><code>code</code></b>' +
                '</span>' +
                '<del>strike</del>0123' +
            '</span>' +
        '</div>';
    t.is(result, expected);
});

test('no children', t => {
    const result = render(<Mark></Mark>);
    const expected = '';
    t.is(result, expected);
});

test('multichar marks', t => {
    const options = {
        '`': {renderer: 'code'},
        '*': {renderer: 'i'},
        '**': {renderer: 'b'},
        '```': {renderer: 'pre', raw: true},
    };
    const str = '**bold** `code` *italic* ```code block```';
    const result = render({str});
    const expected =
        '
' +
            'bold ' +
            'code ' +
            'italic ' +
            '
code block
' +
        '
';
    t.is(result, expected);
});

test('corner case joining code marks', t => {
    const str = '````wat?````';
    const result = render({str});
    const expected =
        '
' +
            '
`wat?</pre>`' +
        '
';
    t.is(result, expected);
});

test('corner case combining style marks', t => {
    const options = {
        '*': {renderer: 'i'},
        '**': {renderer: 'b'},
    };
    const str = '***wat?***';
    const result = render({str});
    const expected =
        '
' +
            '*wat?*' +
        '
';
    t.is(result, expected);
});
<|endoftext|>


<commit_before>/*global describe, it*/
var SubclassError = require('../subclass-error')

describe('SubclassError', function () {
  var ClientError = SubclassError('ClientError', {statusCode: 400})
  var ForbiddenError = SubclassError('ForbiddenError', ClientError, {statusCode: 403})

  describe('constructor', function () {
    it('should throw when subclass name is not provided', function () {
      (function () {
        var unnamed = SubclassError()
        unnamed()
      }).should.throw(/name.*first/i)
    })

    it('should throw when subclass name is not a string', function () {
      (function () {
        var invalidName = SubclassError({})
        invalidName()
      }).should.throw(/expect.*string/i)
    })
  })

  describe('instanceof', function () {
    it('should work', function () {
      var err = new ClientError()
      ;(err instanceof ForbiddenError).should.be.false
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true

      err = new ForbiddenError()
      ;(err instanceof ForbiddenError).should.be.true
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true
    })
  })

  describe('properties', function () {
    it('should be inherited in instances', function () {
      (new ClientError()).statusCode.should.equal(400)
    })

    it('should be inherited in instances of a subclass', function () {
      var FruitError = SubclassError('FruitError', {type: 'food'})
      var AppleError = SubclassError('AppleError', FruitError)
      var err = new AppleError()
      err.type.should.equal('food')
    })
  })

  describe('stack trace', function () {
    it('should be correct', function () {
      var NoFoodError = SubclassError('NoFoodError')
      function eat () { throw new NoFoodError() }
      function hungry () { eat() }

      try {
        hungry()
      } catch (e) {
        var lines = e.stack.split('\n')
        lines[0].should.equal('NoFoodError')
        ;(!!lines[1].match(/at eat .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[2].match(/at hungry .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[3].match(/at Context.<anonymous> .*test\/subclass-error\.js/)).should.be.true
      }
    })
  })
})
<commit_msg>Improve stack trace test<commit_after>/*global describe, it*/
var SubclassError = require('../subclass-error')

describe('SubclassError', function () {
  var ClientError = SubclassError('ClientError', {statusCode: 400})
  var ForbiddenError = SubclassError('ForbiddenError', ClientError, {statusCode: 403})

  describe('constructor', function () {
    it('should throw when subclass name is not provided', function () {
      (function () {
        var unnamed = SubclassError()
        unnamed()
      }).should.throw(/name.*first/i)
    })

    it('should throw when subclass name is not a string', function () {
      (function () {
        var invalidName = SubclassError({})
        invalidName()
      }).should.throw(/expect.*string/i)
    })
  })

  describe('instanceof', function () {
    it('should work', function () {
      var err = new ClientError()
      ;(err instanceof ForbiddenError).should.be.false
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true

      err = new ForbiddenError()
      ;(err instanceof ForbiddenError).should.be.true
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true
    })
  })

  describe('properties', function () {
    it('should be inherited in instances', function () {
      (new ClientError()).statusCode.should.equal(400)
    })

    it('should be inherited in instances of a subclass', function () {
      var FruitError = SubclassError('FruitError', {type: 'food'})
      var AppleError = SubclassError('AppleError', FruitError)
      var err = new AppleError()
      err.type.should.equal('food')
    })
  })

  describe('stack trace', function () {
    it('should be correct', function () {
      var NoFoodError = SubclassError('NoFoodError')
      function eat () { throw new NoFoodError('Nothing in the fridge') }
      function hungry () { eat() }

      try {
        hungry()
      } catch (e) {
        var lines = e.stack.split('\n')
        lines[0].should.equal('NoFoodError: Nothing in the fridge')
        ;(!!lines[1].match(/at eat .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[2].match(/at hungry .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[3].match(/at Context.<anonymous> .*test\/subclass-error\.js/)).should.be.true
      }
    })
  })
})
<|endoftext|>


<commit_before>var assert = require('assert');
var fs = require('fs-extra');
var Tree = require('./utils/builder');
var watch = require('../');

var tree = Tree();
var watcher;

beforeEach(function(done) {
  tree = Tree();
  if (watcher) watcher.close();
  setTimeout(done, 500);
});

after(function() {
  tree && tree.cleanup()
});

describe('watch for files', function() {
  it('should watch a single file and keep watching', function(done) {
    this.timeout(3000);
    var times = 1;
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);
    watcher = watch(fpath, function(evt, name) {
      assert.equal(fpath, name)
      if (times++ >= 3) {
        done();
      }
    });
    tree.modify(file, 100);
    tree.modify(file, 500);
    tree.modify(file, 900);
  });

  it('should watch files inside a directory', function(done) {
    var dir = 'home/a';
    var fpath = tree.getPath('home/a');
    var stack = [
      tree.getPath('home/a/file1'),
      tree.getPath('home/a/file2')
    ];
    watcher = watch(new Buffer(fpath), function(evt, name) {
      stack.splice(stack.indexOf(name), 1);
      if (!stack.length) done();
    });

    tree.modify('home/a/file1', 200);
    tree.modify('home/a/file2', 300);
  });

  it('should watch recursively with `recursive: true` option', function(done) {
    var dir = tree.getPath('home');
    var file = tree.getPath('home/bb/file1');
    watcher = watch(dir, { recursive: true }, function(evt, name) {
      assert.equal(file, name);
      done();
    });

    tree.modify('home/bb/file1', 200);
  });

  it('should ignore duplicate changes', function(done) {
    var file = 'home/a/file2';
    var fpath = tree.getPath(file);
    var times = 0;
    watcher = watch(fpath, function(evt, name) {
      if (fpath == name) times++;
      setTimeout(function() {
        assert(times == 1)
        done();
      }, 200);
    });
    tree.modify(file);
    tree.modify(file);
    tree.modify(file);
  });

});

describe('watch for directoies', function() {

  it('should watch directories inside a directory', function(done) {
    var home = tree.getPath('home');
    var dir = tree.getPath('home/c');

    watcher = watch(home, { recursive: true }, function(evt, name) {
      assert.equal(dir, name);
      done();
    });

    tree.remove('home/c', 300);
  });

  it('should watch new created directories', function(done) {
    var home = tree.getPath('home');
    watcher = watch(home, { recursive: true }, function(evt, name) {
      if (name == tree.getPath('home/new/file1')) {
        done();
      }
    });

    tree.newFile('home/new/file1');
    tree.modify('home/new/file1', 500);
  });
});

describe('events', function() {
  it('should identify `remove` event', function(done) {
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);
    watcher = watch(fpath, function(evt, name) {
      if (evt == 'remove' && name == fpath) done();
    });
    tree.remove(file, 100);
  });

  it('should identify `update` event', function(done) {
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);
    watcher = watch(fpath, function(evt, name) {
      if (evt == 'update' && name == fpath) done();
    });
    tree.modify(file, 100);
  });

  it('should report `update` on new files', function(done) {
    var dir = tree.getPath('home/a');
    var file = 'home/a/newfile' + Date.now();
    var fpath = tree.getPath(file);
    watcher = watch(dir, function(evt, name) {
      if (evt == 'update' && name == fpath) done();
    });
    tree.newFile(file);
  });

});

describe('options', function() {
  describe('encoding', function() {
    it('should accept options as an encoding string', function(done) {
      var dir = tree.getPath('home/a');
      var file = 'home/a/file1';
      var fpath = tree.getPath(file);
      watcher = watch(dir, 'utf8', function(evt, name) {
        assert(name.toString() === fpath);
        done();
      });
      tree.modify(file, 200);
    });

    it('should support buffer encoding', function(done) {
      var dir = tree.getPath('home/a');
      var file = 'home/a/file1';
      var fpath = tree.getPath(file);
      watcher = watch(dir, 'buffer', function(evt, name) {
        assert(Buffer.isBuffer(name), 'not a Buffer')
        assert(name.toString() === fpath);
        done();
      });
      tree.modify(file, 200);
    });
  });

  describe('filter', function() {
    it('should only watch filtered directories', function(done) {
      var shouldModify = true;
      var shouldNotModify = false;

      var option = {
        recursive: true,
        filter: function(name) {
          return !/node_modules/.test(name);
        }
      };

      watcher = watch(tree.getPath('home'), option, function(evt, name) {
        if (/node_modules/.test(name)) {
          shouldNotModify = true;
        } else {
          shouldModify = false;
        }
      });

      tree.modify('home/b/file1', 200);
      tree.modify('home/node_modules/ma/file1', 500);

      setTimeout(function() {
        assert(!shouldModify, 'watch failed');
        assert(!shouldNotModify, 'fail to ingore path `node_modules`');
        done();
      }, 900);
    });

    it('should only report filtered files', function(done) {
      var dir = tree.getPath('home/a');
      var file1 = 'home/a/file1';
      var file2 = 'home/a/file2';

      var options = {
        filter: function(name) {
          return !/file1/.test(name);
        }
      }

      var times = 0;
      watcher = watch(dir, options, function(evt, name) {
        times++;
        if (name == tree.getPath(file2)) {
          assert(times, 1, 'home/a/file1 should be ignored.');
          done();
        }
      });

      tree.modify(file1, 200);
      tree.modify(file2, 400);
    });

    it('should be able to filter with regexp', function(done) {
      var dir = tree.getPath('home/a');
      var file1 = 'home/a/file1';
      var file2 = 'home/a/file2';

      var options = {
        filter:  /file2/
      }

      var times = 0;
      watcher = watch(dir, options, function(evt, name) {
        times++;
        if (name == tree.getPath(file2)) {
          assert(times, 1, 'home/a/file1 should be ignored.');
          done();
        }
      });

      tree.modify(file1, 200);
      tree.modify(file2, 400);
    });

  });
});

describe('parameters', function() {

  it('should throw error on non-existed file', function(done) {
    var somedir = tree.getPath('home/somedir');
    try {
      watcher = watch(somedir);
    } catch(err) {
      done();
    }
  });

  it('should compose array of files or directories', function(done) {
    var file1 = 'home/a/file1';
    var file2 = 'home/a/file2';
    var fpaths = [
      tree.getPath(file1),
      tree.getPath(file2)
    ];

    times = 0;
    watcher = watch(fpaths, function(evt, name) {
      if (fpaths.indexOf(name) !== -1) times++;
      if (times >= 2) done();
    });

    tree.modify(file1);
    tree.modify(file2);
  });

});

describe('watcher object', function() {

  it('should using watcher object to watch', function(done) {
    var dir = tree.getPath('home/a');
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);

    watcher = watch(dir);
    watcher.on('change', function(evt, name) {
      assert(evt == 'update');
      assert(name == fpath);
      done();
    });

    tree.modify(file);
  });

  it('should close a watcher using .close()', function(done) {
    var dir = tree.getPath('home/a');
    var file = 'home/a/file1';
    var times = 0;
    watcher = watch(dir);
    watcher.on('change', function(evt, name) {
      times++;
    });
    watcher.close();

    tree.modify(file);
    tree.modify(file, 300);
    setTimeout(function() {
      assert(watcher.isClosed(), 'watcher should be closed');
      assert(times === 0, 'failed to close the watcher');
      done();
    }, 400);
  });

});
<commit_msg>group tests<commit_after>var assert = require('assert');
var fs = require('fs-extra');
var Tree = require('./utils/builder');
var watch = require('../');

var tree = Tree();
var watcher;

beforeEach(function(done) {
  tree = Tree();
  if (watcher) watcher.close();
  setTimeout(done, 500);
});

after(function() {
  tree && tree.cleanup()
});

describe('watch for files', function() {
  it('should watch a single file and keep watching', function(done) {
    this.timeout(3000);
    var times = 1;
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);
    watcher = watch(fpath, function(evt, name) {
      assert.equal(fpath, name)
      if (times++ >= 3) {
        done();
      }
    });
    tree.modify(file, 100);
    tree.modify(file, 500);
    tree.modify(file, 900);
  });

  it('should watch files inside a directory', function(done) {
    var dir = 'home/a';
    var fpath = tree.getPath('home/a');
    var stack = [
      tree.getPath('home/a/file1'),
      tree.getPath('home/a/file2')
    ];
    watcher = watch(fpath, function(evt, name) {
      stack.splice(stack.indexOf(name), 1);
      if (!stack.length) done();
    });

    tree.modify('home/a/file1', 200);
    tree.modify('home/a/file2', 300);
  });

  it('should ignore duplicate changes', function(done) {
    var file = 'home/a/file2';
    var fpath = tree.getPath(file);
    var times = 0;
    watcher = watch(fpath, function(evt, name) {
      if (fpath == name) times++;
      setTimeout(function() {
        assert(times == 1)
        done();
      }, 200);
    });
    tree.modify(file);
    tree.modify(file);
    tree.modify(file);
  });

});

describe('watch for directoies', function() {

  it('should watch directories inside a directory', function(done) {
    var home = tree.getPath('home');
    var dir = tree.getPath('home/c');

    watcher = watch(home, { recursive: true }, function(evt, name) {
      assert.equal(dir, name);
      done();
    });

    tree.remove('home/c', 300);
  });

  it('should watch new created directories', function(done) {
    var home = tree.getPath('home');
    watcher = watch(home, { recursive: true }, function(evt, name) {
      if (name == tree.getPath('home/new/file1')) {
        done();
      }
    });

    tree.newFile('home/new/file1');
    tree.modify('home/new/file1', 500);
  });
});

describe('events', function() {
  it('should identify `remove` event', function(done) {
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);
    watcher = watch(fpath, function(evt, name) {
      if (evt == 'remove' && name == fpath) done();
    });
    tree.remove(file, 100);
  });

  it('should identify `update` event', function(done) {
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);
    watcher = watch(fpath, function(evt, name) {
      if (evt == 'update' && name == fpath) done();
    });
    tree.modify(file, 100);
  });

  it('should report `update` on new files', function(done) {
    var dir = tree.getPath('home/a');
    var file = 'home/a/newfile' + Date.now();
    var fpath = tree.getPath(file);
    watcher = watch(dir, function(evt, name) {
      if (evt == 'update' && name == fpath) done();
    });
    tree.newFile(file);
  });

});

describe('options', function() {
  describe('recursive', function() {
    it('should watch recursively with `recursive: true` option', function(done) {
      var dir = tree.getPath('home');
      var file = tree.getPath('home/bb/file1');
      watcher = watch(dir, { recursive: true }, function(evt, name) {
        assert.equal(file, name);
        done();
      });
      tree.modify('home/bb/file1', 200);
    });
  });

  describe('encoding', function() {
    it('should accept options as an encoding string', function(done) {
      var dir = tree.getPath('home/a');
      var file = 'home/a/file1';
      var fpath = tree.getPath(file);
      watcher = watch(dir, 'utf8', function(evt, name) {
        assert(name.toString() === fpath);
        done();
      });
      tree.modify(file, 200);
    });

    it('should support buffer encoding', function(done) {
      var dir = tree.getPath('home/a');
      var file = 'home/a/file1';
      var fpath = tree.getPath(file);
      watcher = watch(dir, 'buffer', function(evt, name) {
        assert(Buffer.isBuffer(name), 'not a Buffer')
        assert(name.toString() === fpath);
        done();
      });
      tree.modify(file, 200);
    });
  });

  describe('filter', function() {
    it('should only watch filtered directories', function(done) {
      var shouldModify = true;
      var shouldNotModify = false;

      var option = {
        recursive: true,
        filter: function(name) {
          return !/node_modules/.test(name);
        }
      };

      watcher = watch(tree.getPath('home'), option, function(evt, name) {
        if (/node_modules/.test(name)) {
          shouldNotModify = true;
        } else {
          shouldModify = false;
        }
      });

      tree.modify('home/b/file1', 200);
      tree.modify('home/node_modules/ma/file1', 500);

      setTimeout(function() {
        assert(!shouldModify, 'watch failed');
        assert(!shouldNotModify, 'fail to ingore path `node_modules`');
        done();
      }, 900);
    });

    it('should only report filtered files', function(done) {
      var dir = tree.getPath('home/a');
      var file1 = 'home/a/file1';
      var file2 = 'home/a/file2';

      var options = {
        filter: function(name) {
          return !/file1/.test(name);
        }
      }

      var times = 0;
      watcher = watch(dir, options, function(evt, name) {
        times++;
        if (name == tree.getPath(file2)) {
          assert(times, 1, 'home/a/file1 should be ignored.');
          done();
        }
      });

      tree.modify(file1, 200);
      tree.modify(file2, 400);
    });

    it('should be able to filter with regexp', function(done) {
      var dir = tree.getPath('home/a');
      var file1 = 'home/a/file1';
      var file2 = 'home/a/file2';

      var options = {
        filter:  /file2/
      }

      var times = 0;
      watcher = watch(dir, options, function(evt, name) {
        times++;
        if (name == tree.getPath(file2)) {
          assert(times, 1, 'home/a/file1 should be ignored.');
          done();
        }
      });

      tree.modify(file1, 200);
      tree.modify(file2, 400);
    });

  });
});

describe('parameters', function() {

  it('should throw error on non-existed file', function(done) {
    var somedir = tree.getPath('home/somedir');
    try {
      watcher = watch(somedir);
    } catch(err) {
      done();
    }
  });

  it('should accept filename as Buffer', function(done) {
    var fpath = tree.getPath('home/a/file1');
    watcher = watch(new Buffer(fpath), function(evt, name) {
      assert(name == fpath);
      done();
    });
    tree.modify('home/a/file1', 100);
  });

  it('should compose array of files or directories', function(done) {
    var file1 = 'home/a/file1';
    var file2 = 'home/a/file2';
    var fpaths = [
      tree.getPath(file1),
      tree.getPath(file2)
    ];

    times = 0;
    watcher = watch(fpaths, function(evt, name) {
      if (fpaths.indexOf(name) !== -1) times++;
      if (times >= 2) done();
    });

    tree.modify(file1);
    tree.modify(file2);
  });

});

describe('watcher object', function() {

  it('should using watcher object to watch', function(done) {
    var dir = tree.getPath('home/a');
    var file = 'home/a/file1';
    var fpath = tree.getPath(file);

    watcher = watch(dir);
    watcher.on('change', function(evt, name) {
      assert(evt == 'update');
      assert(name == fpath);
      done();
    });

    tree.modify(file);
  });

  it('should close a watcher using .close()', function(done) {
    var dir = tree.getPath('home/a');
    var file = 'home/a/file1';
    var times = 0;
    watcher = watch(dir);
    watcher.on('change', function(evt, name) {
      times++;
    });
    watcher.close();

    tree.modify(file);
    tree.modify(file, 300);
    setTimeout(function() {
      assert(watcher.isClosed(), 'watcher should be closed');
      assert(times === 0, 'failed to close the watcher');
      done();
    }, 400);
  });

});
<|endoftext|>


<commit_before>/*global describe, it*/
var SubclassError = require('../subclass-error')

describe('SubclassError', function () {
  var ClientError = SubclassError('ClientError', {statusCode: 400})
  var ForbiddenError = SubclassError('ForbiddenError', ClientError, {statusCode: 403})

  describe('constructor', function () {
    it('should throw when subclass name is not provided', function () {
      (function () {
        var unnamed = SubclassError()
        unnamed()
      }).should.throw(/name.*first/i)
    })

    it('should throw when subclass name is not a string', function () {
      (function () {
        var invalidName = SubclassError({})
        invalidName()
      }).should.throw(/expect.*string/i)
    })
  })

  describe('instanceof', function () {
    it('should work', function () {
      var err = new ClientError()
      ;(err instanceof ForbiddenError).should.be.false
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true

      err = new ForbiddenError()
      ;(err instanceof ForbiddenError).should.be.true
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true
    })
  })

  describe('properties', function () {
    it('should be inherited in instances', function () {
      (new ClientError()).statusCode.should.equal(400)
    })

    it('should be inherited in instances of a subclass', function () {
      var FruitError = SubclassError('FruitError', {type: 'food'})
      var AppleError = SubclassError('AppleError', FruitError)
      var err = new AppleError()
      err.type.should.equal('food')
    })
  })

  describe('stack trace', function () {
    it('should be correct', function () {
      var NoFoodError = SubclassError('NoFoodError')
      function eat () {
        throw new NoFoodError()
      }
      function hungry () {
        eat()
      }
      try {
        hungry()
      } catch (e) {
        var lines = e.stack.split('\n')
        lines[0].should.equal('NoFoodError')
        ;(!!lines[1].match(/at eat .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[2].match(/at hungry .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[3].match(/at Context.<anonymous> .*test\/subclass-error\.js/)).should.be.true
      }
    })
  })
})
<commit_msg>Improved style in stack trace test<commit_after>/*global describe, it*/
var SubclassError = require('../subclass-error')

describe('SubclassError', function () {
  var ClientError = SubclassError('ClientError', {statusCode: 400})
  var ForbiddenError = SubclassError('ForbiddenError', ClientError, {statusCode: 403})

  describe('constructor', function () {
    it('should throw when subclass name is not provided', function () {
      (function () {
        var unnamed = SubclassError()
        unnamed()
      }).should.throw(/name.*first/i)
    })

    it('should throw when subclass name is not a string', function () {
      (function () {
        var invalidName = SubclassError({})
        invalidName()
      }).should.throw(/expect.*string/i)
    })
  })

  describe('instanceof', function () {
    it('should work', function () {
      var err = new ClientError()
      ;(err instanceof ForbiddenError).should.be.false
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true

      err = new ForbiddenError()
      ;(err instanceof ForbiddenError).should.be.true
      ;(err instanceof ClientError).should.be.true
      ;(err instanceof Error).should.be.true
    })
  })

  describe('properties', function () {
    it('should be inherited in instances', function () {
      (new ClientError()).statusCode.should.equal(400)
    })

    it('should be inherited in instances of a subclass', function () {
      var FruitError = SubclassError('FruitError', {type: 'food'})
      var AppleError = SubclassError('AppleError', FruitError)
      var err = new AppleError()
      err.type.should.equal('food')
    })
  })

  describe('stack trace', function () {
    it('should be correct', function () {
      var NoFoodError = SubclassError('NoFoodError')
      function eat () { throw new NoFoodError() }
      function hungry () { eat() }

      try {
        hungry()
      } catch (e) {
        var lines = e.stack.split('\n')
        lines[0].should.equal('NoFoodError')
        ;(!!lines[1].match(/at eat .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[2].match(/at hungry .*test\/subclass-error\.js/)).should.be.true
        ;(!!lines[3].match(/at Context.<anonymous> .*test\/subclass-error\.js/)).should.be.true
      }
    })
  })
})
<|endoftext|>


<commit_before>var dotest = require ('dotest');
var app = require ('./');

// Setup
// $ EUROPEANA_KEY=abc123 npm test
var apikey = process.env.EUROPEANA_APIKEY || null;
var timeout = process.env.EUROPEANA_TIMEOUT || 5000;

var europeana = app (apikey, timeout);

dotest.add ('Module', function (test) {
  test ()
    .isFunction ('fail', 'exports', app)
    .isFunction ('fail', 'module', europeana)
    .done ();
});

dotest.add ('search', function (test) {
  var props = {
    query: 'who:"laurent de la hyre"'
  };

  europeana ('search', props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .done ();
  });
});

dotest.add ('record', function (test) {
  var record = '9200365/BibliographicResource_1000055039444';
  var props = {
    profile: 'params'
  };

  europeana ('record/' + record, props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .done ();
  });
});

dotest.add ('translateQuery', function (test) {
  var props = {
    languageCodes: 'nl,en,hu',
    term: 'painting'
  };

  europeana ('translateQuery', props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .isArray ('warn', 'data.translations', data && data.translations)
      .done ();
  });
});

dotest.add ('providers normal', function (test) {
  europeana ('providers', function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .isArray ('warn', 'data.items', data && data.items)
      .done ();
  });
});

dotest.add ('providers params', function (test) {
  var params = {
    pagesize: 3
  };

  europeana ('providers', params, function (err, data) {
    var items = data && data.items;

    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .isArray ('warn', 'data.items', items)
      .isExactly ('warn', 'data.items.length', items && items.length, 3)
      .done ();
  });
});

dotest.add ('Error: API error', function (test) {
  europeana ('record/-', function (err, data) {
    test ()
      .isError ('fail', 'err', err)
      .isExactly ('fail', 'err.message', err && err.message, 'API error')
      .isNumber ('fail', 'err.code', err && err.code)
      .isString ('fail', 'err.error', err && err.error)
      .isUndefined ('fail', 'data', data)
      .done ();
  });
});

dotest.add ('Error: apikey missing', function (test) {
  var tmp = app ();

  tmp ('providers', function (err, data) {
    test ()
      .isError ('fail', 'err', err)
      .isExactly ('fail', 'err.message', err && err.message, 'apikey missing')
      .isUndefined ('fail', 'data', data)
      .done ();
  });
});

/*
// Suggestions in unavailable
// http://labs.europeana.eu/api/suggestions
dotest.add ('suggestions', function (test) {
  var props = {
    query: 'laurent de la hyre',
    rows: 10
  };

  app ('suggestions', props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .done ();
  });
});
*/

// Start the tests
dotest.run ();
<commit_msg>Test(tests): Add Error: request failed<commit_after>var dotest = require ('dotest');
var app = require ('./');

// Setup
// $ EUROPEANA_KEY=abc123 npm test
var apikey = process.env.EUROPEANA_APIKEY || null;
var timeout = process.env.EUROPEANA_TIMEOUT || 5000;

var europeana = app (apikey, timeout);

dotest.add ('Module', function (test) {
  test ()
    .isFunction ('fail', 'exports', app)
    .isFunction ('fail', 'module', europeana)
    .done ();
});

dotest.add ('search', function (test) {
  var props = {
    query: 'who:"laurent de la hyre"'
  };

  europeana ('search', props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .done ();
  });
});

dotest.add ('record', function (test) {
  var record = '9200365/BibliographicResource_1000055039444';
  var props = {
    profile: 'params'
  };

  europeana ('record/' + record, props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .done ();
  });
});

dotest.add ('translateQuery', function (test) {
  var props = {
    languageCodes: 'nl,en,hu',
    term: 'painting'
  };

  europeana ('translateQuery', props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .isArray ('warn', 'data.translations', data && data.translations)
      .done ();
  });
});

dotest.add ('providers normal', function (test) {
  europeana ('providers', function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .isArray ('warn', 'data.items', data && data.items)
      .done ();
  });
});

dotest.add ('providers params', function (test) {
  var params = {
    pagesize: 3
  };

  europeana ('providers', params, function (err, data) {
    var items = data && data.items;

    test (err)
      .isObject ('fail', 'data', data)
      .isNotEmpty ('warn', 'data', data)
      .isArray ('warn', 'data.items', items)
      .isExactly ('warn', 'data.items.length', items && items.length, 3)
      .done ();
  });
});

dotest.add ('Error: API error', function (test) {
  europeana ('record/-', function (err, data) {
    test ()
      .isError ('fail', 'err', err)
      .isExactly ('fail', 'err.message', err && err.message, 'API error')
      .isNumber ('fail', 'err.code', err && err.code)
      .isString ('fail', 'err.error', err && err.error)
      .isUndefined ('fail', 'data', data)
      .done ();
  });
});

dotest.add ('Error: request failed', function (test) {
  var tmp = app (apikey, 1);

  tmp ('providers', function (err, data) (
    test ()
      .isError ('fail', 'err', err)
      .isExactly ('fail', 'err.message', err && err.message, 'request failed')
      .isError ('fail', 'err.error', err && err.error)
      .isUndefined ('fail', 'data', data)
      .done ();
  });
});

dotest.add ('Error: apikey missing', function (test) {
  var tmp = app ();

  tmp ('providers', function (err, data) {
    test ()
      .isError ('fail', 'err', err)
      .isExactly ('fail', 'err.message', err && err.message, 'apikey missing')
      .isUndefined ('fail', 'data', data)
      .done ();
  });
});

/*
// Suggestions in unavailable
// http://labs.europeana.eu/api/suggestions
dotest.add ('suggestions', function (test) {
  var props = {
    query: 'laurent de la hyre',
    rows: 10
  };

  app ('suggestions', props, function (err, data) {
    test (err)
      .isObject ('fail', 'data', data)
      .done ();
  });
});
*/

// Start the tests
dotest.run ();
<|endoftext|>


<commit_before>// Core

QUnit.test( "className Query", function( assert ) {
  assert.equal($('.class-fixture').length, 1, "className Passed!" );
});

QUnit.test( "id Query", function( assert ) {
  assert.equal($('#id-fixture').length, 1, "id Passed!" );
});

QUnit.test( "qSA Query", function( assert ) {
  assert.equal($('.qsa-fixture').length, 2, "qSA Passed!" );
});

QUnit.test( "domNode Query", function( assert ) {
  assert.equal($($('.qsa-fixture')[0]).length, 1, " domNode Passed!" );
});

QUnit.test( "HTML Query/Init", function( assert ) {
  assert.equal($('
').length, 1, "HTML Passed!" );
});

// AJAX

QUnit.test( "Ajax", function( assert ) {

  QUnit.stop();

  $.ajax({
    type: 'GET',
    url: 'ajax-fixture.html',
    success: function(data) {
      QUnit.ok(true, "Ajax Success Passed");
      QUnit.start();
    }
  });

  QUnit.stop();

  $.ajax({
    type: 'GET',
    url: 'missing-fixture.html',
    error: function(error) {
      QUnit.ok(true, "Ajax Error Passed = " + error);
      QUnit.start();
    }
  });

});

//Attributes

QUnit.test( "addClass", function( assert ) {
  $('.class-fixture').addClass('add-class');
  assert.equal($('.add-class').length, 1, "addClass Passed!" );
  $('.qsa-fixture').addClass('add-class-multiple');
  assert.equal($('.add-class-multiple').length, 2, "addClass multiple Passed!" );
});

QUnit.test( "attr", function( assert ) {
  var testAttr = $('.attr-fixture').attr('success');
  assert.equal(testAttr, 'get', "attr get Passed!" );
  $('.attr-fixture').attr('success','set');
  testAttr = $('.attr-fixture').attr('success');
  assert.equal(testAttr, 'set', "attr set Passed!" );
});

QUnit.test( "hasClass", function( assert ) {
  var hasClass = $('.attr-fixture').hasClass('has-class');
  assert.equal(hasClass, true, "hasClass Passed!" );
});

QUnit.test( "prop", function( assert ) {
  assert.equal($('.prop-fixture').prop('checked'), true, "prop Passed!" );
});

QUnit.test( "removeAttr", function( assert ) {
  $('.attr-fixture').removeAttr('success');
  assert.equal($('.attr-fixture').attr('success'), undefined, "removeAttr Passed!" );
});

QUnit.test( "removeClass", function( assert ) {
  $('.attr-fixture').removeClass('has-class');
  assert.equal($('.attr-fixture').hasClass('has-class'), false, "removeClass Passed!" );
});

//Collection

QUnit.test( "each", function( assert ) {
  var arrayFixture = [];
  $('.qsa-fixture').each(function(v,i,a){
    arrayFixture.push(i);
  });
  assert.equal(arrayFixture.length, 2, "each Passed!" );
});

QUnit.test( "eq", function( assert ) {
  assert.equal($('#qunit-fixture div').eq(1)[0], $('#id-fixture')[0], "eq Passed!" );
});

QUnit.test( "filter", function( assert ) {
  var arrayFixture = $('#qunit-fixture div').filter('.has-class');
  assert.equal(arrayFixture.length, 1, "filter(selector) Passed!" );
  arrayFixture = $('#qunit-fixture div').filter(function(e){
    return $(e).hasClass('qsa-fixture');
  });
  assert.equal(arrayFixture.length, 2, "filter(fn) Passed!" );
});

QUnit.test( "first", function( assert ) {
  var firstFixture = $('#qunit-fixture div').first();
  assert.equal(firstFixture.hasClass('class-fixture'), true, "first Passed!" );
});

QUnit.test( "get", function( assert ) {
  var getFixture = $('#qunit-fixture div').get(1);
  assert.equal($(getFixture).attr('id'), 'id-fixture', "get Passed!" );
});

QUnit.test( "index", function( assert ) {
  var indexFixture = $('.qsa-fixture').index();
  assert.equal(indexFixture, 2, "index Passed!" );
});

QUnit.test( "last", function( assert ) {
  var lastFixture = $('#qunit-fixture div').last();
  assert.equal($(lastFixture).hasClass('has-class'), true, "index Passed!" );
});

QUnit.test( "add", function( assert ) {
  var addFixture = $('#id-fixture').add( $('.class-fixture') );
  assert.equal(addFixture.length, 2, "add(one) Passed!" );
  addFixture = $('#id-fixture').add( $('a').eq(0) , $('a').eq(1) );
  assert.equal(addFixture.length, 3, "add(two) Passed!" );
  addFixture = $('#id-fixture').add( $('#qunit-fixture a') , $('#qunit-fixture input') );
  assert.equal(addFixture.length, 9, "add(collections) Passed!" );
  addFixture = $('#qunit-fixture a').first().add( $('#qunit-fixture a') );
  assert.equal(addFixture.length, 4, "add(no duplicates) Passed!" );
  addFixture = $('#id-fixture').add( "#qunit-fixture a" );
  assert.equal(addFixture.length, 5, "add(allow selector string) Passed!" );
});

//CSS

QUnit.test( "css", function( assert ) {
  assert.equal($('.css-fixture').css('height'), '50px', "css read Passed!" );
  $('.css-fixture').css('height','100px');
  assert.equal($('.css-fixture').css('height'), '100px', "css write Passed!" );
  $('.css-fixture').css({height: '50px', width: '100px'});
  assert.equal($('.css-fixture').css('width'), '100px', "css write many Passed!" );
});

//Data

QUnit.test( "data", function( assert ) {
  assert.equal($('.attr-fixture').data('index'), 5, "data read Passed!" );
  $('.attr-fixture').data('index',10);
  assert.equal($('.attr-fixture').data('index'), 10, "data set Passed!" );
  $('.attr-fixture').removeData('index');
  assert.notEqual($('.attr-fixture').data('index'), 10, "data remove Passed!" );
});

//Dimensions

QUnit.test( "height", function( assert ) {
  assert.equal($('.css-fixture').height(), 100, "height Passed!" );
});

QUnit.test( "innerHeight", function( assert ) {
  assert.equal($('.css-fixture').innerHeight(), 90, "innerHeight Passed!" );
});

QUnit.test( "outerHeight", function( assert ) {
  assert.equal($('.css-fixture').outerHeight(), 100, "outerHeight Passed!" );
  assert.equal($('.css-fixture').outerHeight(true), 140, "outerHeight(margins) Passed!" );
});

QUnit.test( "width", function( assert ) {
  assert.equal($('.css-fixture').width(), 100, "width Passed!" );
});

QUnit.test( "innerWidth", function( assert ) {
  assert.equal($('.css-fixture').innerWidth(), 90, "innerWidth Passed!" );
});

QUnit.test( "outerWidth", function( assert ) {
  assert.equal($('.css-fixture').outerWidth(), 100, "outerWidth Passed!" );
  assert.equal($('.css-fixture').outerWidth(true), 140, "outerWidth(margins) Passed!" );
});

//Events

QUnit.test( "on", function( assert ) {
  var i = 1;
  $('.event-fixture').on('click', function(){
    i++;
    this.textContent = i;
  });
  $('.event-fixture').trigger('click');
  assert.equal($('.event-fixture')[0].textContent, 2, "on Passed!" );
});

QUnit.test( "on(delegate)", function( assert ) {
  var i = 1;
  $('#qunit-fixture').on('click','.delegate-fixture', function(){
    i++;
    this.textContent = i;
  });
  $('.delegate-trigger').trigger('click');
  assert.equal($('.delegate-fixture')[0].textContent, 2, "on(delegate) Passed!" );
});

QUnit.test( "off", function( assert ) {
  var i = 1;
  $('.off-fixture').on('click', function(){
    i++;
    this.textContent = i;
  });
  $('.off-fixture').trigger('click');
  $('.off-fixture').off('click');
  $('.off-fixture').trigger('click');
  assert.equal($('.off-fixture')[0].textContent, 2, "on Passed!" );
});

QUnit.test( "trigger", function( assert ) {
  var i = 1;
  $('.trigger-fixture').on('click', function(){
    i++;
    this.textContent = i;
  });
  $('.trigger-fixture').trigger('click');
  assert.equal($('.trigger-fixture')[0].textContent, 2, "trigger Passed!" );
});

//Forms

QUnit.test( "serialize", function( assert ) {
  var data = $('.form-fixture').serialize();
  assert.equal(data, "text=text&hidden=5", "serialize Passed!" );
});

QUnit.test( "val", function( assert ) {
  assert.equal($('input[type=text]').val(), "text", "val get Passed!" );
  $('input[type=text]').val(0);
  assert.equal($('input[type=text]').val(), 0, "val set Passed!" );
});

//Traversal

QUnit.test( "children", function( assert ) {
  assert.equal($('#qunit-fixture').children().length, 12, "children Passed!" );
  assert.equal($('#qunit-fixture').children('div').length, 5, "children(selector) Passed!" );
});

QUnit.test( "find", function( assert ) {
  assert.equal($('.form-fixture').find('input[type=hidden]').length, 1, "find Passed!" );
});

QUnit.test( "has", function( assert ) {
  assert.equal($('.form-fixture').has('input').length, true, "has Passed!" );
});

QUnit.test( "next", function( assert ) {
  assert.equal($('.form-fixture input').next().val(), 'text', "next Passed!" );
});

QUnit.test( "not", function( assert ) {
  assert.equal($('#qunit-fixture div').not('.qsa-fixture').length, 3, "not Passed!" );
});

QUnit.test( "parent", function( assert ) {
  assert.equal($('.qsa-fixture').parent()[0].id, 'qunit-fixture', "parent Passed!" );
});

QUnit.test( "parents", function( assert ) {
  assert.equal($('input[type=hidden]').parents('#qunit-fixture').length, 1, "parents Passed!" );
});

QUnit.test( "prev", function( assert ) {
  assert.equal($('.form-fixture input[type=text]').prev().val(), 5, "prev Passed!" );
});

QUnit.test( "siblings", function( assert ) {
  assert.equal($('#id-fixture').siblings().length, 11, "siblings Passed!" );
});

//Manipulation

QUnit.test( "append", function( assert ) {
  $('#qunit-fixture').append('
');
  assert.equal($('.test').length, 1, "append Passed!" );
});

QUnit.test( "appendTo", function( assert ) {
  $('
').appendTo('#qunit-fixture');
  assert.equal($('.test').length, 1, "appendTo Passed!" );
});

QUnit.test( "clone", function( assert ) {
  assert.equal($('.class-fixture').clone()[0].className, 'class-fixture', "clone Passed!" );
});

QUnit.test( "empty", function( assert ) {
  assert.equal($('.form-fixture').empty().children().length, 0, "empty Passed!" );
});

QUnit.test( "html", function( assert ) {
  $('.class-fixture').html('
');
  assert.equal($('.html-test').length, 1, "html Passed!" );
});

QUnit.test( "insertAfter", function( assert ) {
  $('

').insertAfter('input[type=hidden]');
  assert.equal($('.test').index(), 1, "insertAfter Passed!" );
});

QUnit.test( "insertBefore", function( assert ) {
  $('

').insertBefore('input[type=submit]');
  assert.equal($('.test').index(), 2, "insertBefore Passed!" );
});

QUnit.test( "prepend", function( assert ) {
  $('.form-fixture').prepend('

');
  assert.equal($('.test').index(), 0, "prepend Passed!" );
});

QUnit.test( "prependTo", function( assert ) {
  $('

').prependTo('.form-fixture');
  assert.equal($('.test').index(), 0, "prependTo Passed!" );
});

QUnit.test( "remove", function( assert ) {
  $('.class-fixture').remove();
  assert.equal($('.class-fixture').length, 0, "remove Passed!" );
});

QUnit.test( "text", function( assert ) {
  $('.class-fixture').text('Text Content');
  assert.equal($('.class-fixture')[0].textContent, "Text Content", "text Passed!" );
});

//Utils

QUnit.test( "$.each", function( assert ) {
  var test = 0;
  $.each(new Array(3), function(){
    test++;
  });
  assert.equal(test, 3, "$.each Passed!" );
});

QUnit.test( "$.extend", function( assert ) {
  var orig = {}, test = {count: 3};
  $.extend(orig,test);
  assert.equal(orig.count, 3, "$.extend Passed!" );
});

QUnit.test( "$.matches", function( assert ) {
  var test = $('
')[0], selector = ".test";
  assert.equal($.matches(test,selector), true, "$.matches Passed!" );
});

QUnit.test( "$.parseHTML", function( assert ) {
  assert.equal($.parseHTML('')[0].outerHTML, '' , "$.parseHTML Passed!" );
});<commit_msg>add tests for parents, closest<commit_after>// Core

QUnit.test( "className Query", function( assert ) {
  assert.equal($('.class-fixture').length, 1, "className Passed!" );
});

QUnit.test( "id Query", function( assert ) {
  assert.equal($('#id-fixture').length, 1, "id Passed!" );
});

QUnit.test( "qSA Query", function( assert ) {
  assert.equal($('.qsa-fixture').length, 2, "qSA Passed!" );
});

QUnit.test( "domNode Query", function( assert ) {
  assert.equal($($('.qsa-fixture')[0]).length, 1, " domNode Passed!" );
});

QUnit.test( "HTML Query/Init", function( assert ) {
  assert.equal($('
').length, 1, "HTML Passed!" );
});

// AJAX

QUnit.test( "Ajax", function( assert ) {

  QUnit.stop();

  $.ajax({
    type: 'GET',
    url: 'ajax-fixture.html',
    success: function(data) {
      QUnit.ok(true, "Ajax Success Passed");
      QUnit.start();
    }
  });

  QUnit.stop();

  $.ajax({
    type: 'GET',
    url: 'missing-fixture.html',
    error: function(error) {
      QUnit.ok(true, "Ajax Error Passed = " + error);
      QUnit.start();
    }
  });

});

//Attributes

QUnit.test( "addClass", function( assert ) {
  $('.class-fixture').addClass('add-class');
  assert.equal($('.add-class').length, 1, "addClass Passed!" );
  $('.qsa-fixture').addClass('add-class-multiple');
  assert.equal($('.add-class-multiple').length, 2, "addClass multiple Passed!" );
});

QUnit.test( "attr", function( assert ) {
  var testAttr = $('.attr-fixture').attr('success');
  assert.equal(testAttr, 'get', "attr get Passed!" );
  $('.attr-fixture').attr('success','set');
  testAttr = $('.attr-fixture').attr('success');
  assert.equal(testAttr, 'set', "attr set Passed!" );
});

QUnit.test( "hasClass", function( assert ) {
  var hasClass = $('.attr-fixture').hasClass('has-class');
  assert.equal(hasClass, true, "hasClass Passed!" );
});

QUnit.test( "prop", function( assert ) {
  assert.equal($('.prop-fixture').prop('checked'), true, "prop Passed!" );
});

QUnit.test( "removeAttr", function( assert ) {
  $('.attr-fixture').removeAttr('success');
  assert.equal($('.attr-fixture').attr('success'), undefined, "removeAttr Passed!" );
});

QUnit.test( "removeClass", function( assert ) {
  $('.attr-fixture').removeClass('has-class');
  assert.equal($('.attr-fixture').hasClass('has-class'), false, "removeClass Passed!" );
});

//Collection

QUnit.test( "add", function( assert ) {
  var addFixture = $('#id-fixture').add( $('.class-fixture') );
  assert.equal(addFixture.length, 2, "add(one) Passed!" );
  addFixture = $('#id-fixture').add( $('a').eq(0) , $('a').eq(1) );
  assert.equal(addFixture.length, 3, "add(two) Passed!" );
  addFixture = $('#id-fixture').add( $('#qunit-fixture a') , $('#qunit-fixture input') );
  assert.equal(addFixture.length, 9, "add(collections) Passed!" );
  addFixture = $('#qunit-fixture a').first().add( $('#qunit-fixture a') );
  assert.equal(addFixture.length, 4, "add(no duplicates) Passed!" );
  addFixture = $('#id-fixture').add( "#qunit-fixture a" );
  assert.equal(addFixture.length, 5, "add(allow selector string) Passed!" );
});

QUnit.test( "each", function( assert ) {
  var arrayFixture = [];
  $('.qsa-fixture').each(function(v,i,a){
    arrayFixture.push(i);
  });
  assert.equal(arrayFixture.length, 2, "each Passed!" );
});

QUnit.test( "eq", function( assert ) {
  assert.equal($('#qunit-fixture div').eq(1)[0], $('#id-fixture')[0], "eq Passed!" );
});

QUnit.test( "filter", function( assert ) {
  var arrayFixture = $('#qunit-fixture div').filter('.has-class');
  assert.equal(arrayFixture.length, 1, "filter(selector) Passed!" );
  arrayFixture = $('#qunit-fixture div').filter(function(e){
    return $(e).hasClass('qsa-fixture');
  });
  assert.equal(arrayFixture.length, 2, "filter(fn) Passed!" );
});

QUnit.test( "first", function( assert ) {
  var firstFixture = $('#qunit-fixture div').first();
  assert.equal(firstFixture.hasClass('class-fixture'), true, "first Passed!" );
});

QUnit.test( "get", function( assert ) {
  var getFixture = $('#qunit-fixture div').get(1);
  assert.equal($(getFixture).attr('id'), 'id-fixture', "get Passed!" );
});

QUnit.test( "index", function( assert ) {
  var indexFixture = $('.qsa-fixture').index();
  assert.equal(indexFixture, 2, "index Passed!" );
});

QUnit.test( "last", function( assert ) {
  var lastFixture = $('#qunit-fixture div').last();
  assert.equal($(lastFixture).hasClass('has-class'), true, "index Passed!" );
});

//CSS

QUnit.test( "css", function( assert ) {
  assert.equal($('.css-fixture').css('height'), '50px', "css read Passed!" );
  $('.css-fixture').css('height','100px');
  assert.equal($('.css-fixture').css('height'), '100px', "css write Passed!" );
  $('.css-fixture').css({height: '50px', width: '100px'});
  assert.equal($('.css-fixture').css('width'), '100px', "css write many Passed!" );
});

//Data

QUnit.test( "data", function( assert ) {
  assert.equal($('.attr-fixture').data('index'), 5, "data read Passed!" );
  $('.attr-fixture').data('index',10);
  assert.equal($('.attr-fixture').data('index'), 10, "data set Passed!" );
  $('.attr-fixture').removeData('index');
  assert.notEqual($('.attr-fixture').data('index'), 10, "data remove Passed!" );
});

//Dimensions

QUnit.test( "height", function( assert ) {
  assert.equal($('.css-fixture').height(), 100, "height Passed!" );
});

QUnit.test( "innerHeight", function( assert ) {
  assert.equal($('.css-fixture').innerHeight(), 90, "innerHeight Passed!" );
});

QUnit.test( "outerHeight", function( assert ) {
  assert.equal($('.css-fixture').outerHeight(), 100, "outerHeight Passed!" );
  assert.equal($('.css-fixture').outerHeight(true), 140, "outerHeight(margins) Passed!" );
});

QUnit.test( "width", function( assert ) {
  assert.equal($('.css-fixture').width(), 100, "width Passed!" );
});

QUnit.test( "innerWidth", function( assert ) {
  assert.equal($('.css-fixture').innerWidth(), 90, "innerWidth Passed!" );
});

QUnit.test( "outerWidth", function( assert ) {
  assert.equal($('.css-fixture').outerWidth(), 100, "outerWidth Passed!" );
  assert.equal($('.css-fixture').outerWidth(true), 140, "outerWidth(margins) Passed!" );
});

//Events

QUnit.test( "on", function( assert ) {
  var i = 1;
  $('.event-fixture').on('click', function(){
    i++;
    this.textContent = i;
  });
  $('.event-fixture').trigger('click');
  assert.equal($('.event-fixture')[0].textContent, 2, "on Passed!" );
});

QUnit.test( "on(delegate)", function( assert ) {
  var i = 1;
  $('#qunit-fixture').on('click','.delegate-fixture', function(){
    i++;
    this.textContent = i;
  });
  $('.delegate-trigger').trigger('click');
  assert.equal($('.delegate-fixture')[0].textContent, 2, "on(delegate) Passed!" );
});

QUnit.test( "off", function( assert ) {
  var i = 1;
  $('.off-fixture').on('click', function(){
    i++;
    this.textContent = i;
  });
  $('.off-fixture').trigger('click');
  $('.off-fixture').off('click');
  $('.off-fixture').trigger('click');
  assert.equal($('.off-fixture')[0].textContent, 2, "on Passed!" );
});

QUnit.test( "trigger", function( assert ) {
  var i = 1;
  $('.trigger-fixture').on('click', function(){
    i++;
    this.textContent = i;
  });
  $('.trigger-fixture').trigger('click');
  assert.equal($('.trigger-fixture')[0].textContent, 2, "trigger Passed!" );
});

//Forms

QUnit.test( "serialize", function( assert ) {
  var data = $('.form-fixture').serialize();
  assert.equal(data, "text=text&hidden=5", "serialize Passed!" );
});

QUnit.test( "val", function( assert ) {
  assert.equal($('input[type=text]').val(), "text", "val get Passed!" );
  $('input[type=text]').val(0);
  assert.equal($('input[type=text]').val(), 0, "val set Passed!" );
});

//Traversal

QUnit.test( "children", function( assert ) {
  assert.equal($('#qunit-fixture').children().length, 12, "children Passed!" );
  assert.equal($('#qunit-fixture').children('div').length, 5, "children(selector) Passed!" );
});

QUnit.test( "closest", function( assert ) {
  assert.equal($('input.prop-fixture').closest('div').length, 1, "closest Passed!" );
});

QUnit.test( "find", function( assert ) {
  assert.equal($('.form-fixture').find('input[type=hidden]').length, 1, "find Passed!" );
});

QUnit.test( "has", function( assert ) {
  assert.equal($('.form-fixture').has('input').length, true, "has Passed!" );
});

QUnit.test( "next", function( assert ) {
  assert.equal($('.form-fixture input').next().val(), 'text', "next Passed!" );
});

QUnit.test( "not", function( assert ) {
  assert.equal($('#qunit-fixture div').not('.qsa-fixture').length, 3, "not Passed!" );
});

QUnit.test( "parent", function( assert ) {
  assert.equal($('.qsa-fixture').parent()[0].id, 'qunit-fixture', "parent Passed!" );
});

QUnit.test( "parents", function( assert ) {
  assert.equal($('.form-fixture input').parents().length, 4, "parents Passed!" );
  assert.equal($('.form-fixture input').parents('div, form').length, 2, "parents(selector) Passed!" );
});

QUnit.test( "prev", function( assert ) {
  assert.equal($('.form-fixture input[type=text]').prev().val(), 5, "prev Passed!" );
});

QUnit.test( "siblings", function( assert ) {
  assert.equal($('#id-fixture').siblings().length, 11, "siblings Passed!" );
});

//Manipulation

QUnit.test( "append", function( assert ) {
  $('#qunit-fixture').append('
');
  assert.equal($('.test').length, 1, "append Passed!" );
});

QUnit.test( "appendTo", function( assert ) {
  $('
').appendTo('#qunit-fixture');
  assert.equal($('.test').length, 1, "appendTo Passed!" );
});

QUnit.test( "clone", function( assert ) {
  assert.equal($('.class-fixture').clone()[0].className, 'class-fixture', "clone Passed!" );
});

QUnit.test( "empty", function( assert ) {
  assert.equal($('.form-fixture').empty().children().length, 0, "empty Passed!" );
});

QUnit.test( "html", function( assert ) {
  $('.class-fixture').html('
');
  assert.equal($('.html-test').length, 1, "html Passed!" );
});

QUnit.test( "insertAfter", function( assert ) {
  $('

').insertAfter('input[type=hidden]');
  assert.equal($('.test').index(), 1, "insertAfter Passed!" );
});

QUnit.test( "insertBefore", function( assert ) {
  $('

').insertBefore('input[type=submit]');
  assert.equal($('.test').index(), 2, "insertBefore Passed!" );
});

QUnit.test( "prepend", function( assert ) {
  $('.form-fixture').prepend('

');
  assert.equal($('.test').index(), 0, "prepend Passed!" );
});

QUnit.test( "prependTo", function( assert ) {
  $('

').prependTo('.form-fixture');
  assert.equal($('.test').index(), 0, "prependTo Passed!" );
});

QUnit.test( "remove", function( assert ) {
  $('.class-fixture').remove();
  assert.equal($('.class-fixture').length, 0, "remove Passed!" );
});

QUnit.test( "text", function( assert ) {
  $('.class-fixture').text('Text Content');
  assert.equal($('.class-fixture')[0].textContent, "Text Content", "text Passed!" );
});

//Utils

QUnit.test( "$.each", function( assert ) {
  var test = 0;
  $.each(new Array(3), function(){
    test++;
  });
  assert.equal(test, 3, "$.each Passed!" );
});

QUnit.test( "$.extend", function( assert ) {
  var orig = {}, test = {count: 3};
  $.extend(orig,test);
  assert.equal(orig.count, 3, "$.extend Passed!" );
});

QUnit.test( "$.matches", function( assert ) {
  var test = $('
')[0], selector = ".test";
  assert.equal($.matches(test,selector), true, "$.matches Passed!" );
});

QUnit.test( "$.parseHTML", function( assert ) {
  assert.equal($.parseHTML('')[0].outerHTML, '' , "$.parseHTML Passed!" );
});<|endoftext|>