Skip to content
This repository has been archived by the owner on Aug 1, 2020. It is now read-only.

Commit

Permalink
test: add test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Mar 11, 2018
1 parent 6ecdc63 commit 6a7f524
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"mocha": true
},
"globals": {
"$": true,
"expect": true
},
"rules": {
"no-unused-expressions": "off"
}
}
53 changes: 53 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
describe('viewer', () => {
const createImage = () => {
const container = document.createElement('div');
const image = document.createElement('img');

image.src = '/base/docs/images/tibet-1.jpg';
container.appendChild(image);
document.body.appendChild(container);

return image;
};

it('should register as a plugin correctly', () => {
expect($.fn.viewer).to.be.a('function');
expect($.fn.viewer.Constructor).to.be.a('function');
expect($.fn.viewer.noConflict).to.be.a('function');
expect($.fn.viewer.setDefaults).to.be.a('function');
});

it('should remove data after destroyed', () => {
const $image = $(createImage());

$image.viewer();
expect($image.data('viewer')).to.be.an.instanceof($.fn.viewer.Constructor);
$image.viewer('destroy');
expect($image.data('viewer')).to.be.undefined;
});

it('should apply the given option', (done) => {
$(createImage()).viewer({
inline: true,

ready() {
done();
},
});
});

it('should execute the given method', (done) => {
$(createImage()).viewer({
shown() {
done();
},
}).viewer('show');
});

it('should trigger the binding event', (done) => {
$(createImage()).one('ready', (event) => {
expect(event.type).to.equal('ready');
done();
}).viewer('show');
});
});
42 changes: 42 additions & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const puppeteer = require('puppeteer');
const rollupConfig = require('../rollup.config');

process.env.CHROME_BIN = puppeteer.executablePath();

module.exports = (config) => {
config.set({
autoWatch: false,
basePath: '..',
browsers: ['ChromeHeadlessWithoutSandbox'],
customLaunchers: {
ChromeHeadlessWithoutSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox'],
},
},
files: [
'node_modules/jquery/dist/jquery.js',
'dist/viewer.css',
'dist/viewer.js',
'test/index.js',
{
pattern: 'docs/images/*',
included: false,
},
],
frameworks: ['mocha', 'chai'],
preprocessors: {
'test/index.js': ['rollup'],
},
reporters: ['mocha'],
rollupPreprocessor: {
plugins: rollupConfig.plugins,
output: {
format: 'iife',
name: 'Viewer',
sourcemap: 'inline',
},
},
singleRun: true,
});
};

0 comments on commit 6a7f524

Please sign in to comment.