Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-fixtures

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-fixtures - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

27

fixtures.js

@@ -40,21 +40,22 @@ "use strict";

};
self.sandbox = function(attributes){
var attributesToSet = attributes || {};
return jQuery('<div id="sandbox" />').attr(attributesToSet);
};
var createContainer = function(html){
var container;
if(html instanceof jQuery){
container = jQuery('<div id="' + self.containerId + '" />');
container.html(html);
} else{
container = '<div id="' + self.containerId + '">' + html + '</div>'
}
jQuery('body').append(container);
var iframe = document.createElement('iframe');
iframe.setAttribute("id", self.containerId);
$('body').append(iframe);
var doc = iframe.contentWindow || iframe.contentDocument;
doc = doc.document ? doc.document : doc;
doc.open();
doc.write(html);
doc.close();
};
var addToContainer = function(html){
var container = jQuery('body').find('#' + self.containerId).append(html);
var container = jQuery('#' + self.containerId);
if (!container.length){
createContainer(html);
}
else{
container.contents().find('body').append(html);
}
};

@@ -61,0 +62,0 @@ var getFixtureHtml = function(url){

@@ -6,9 +6,9 @@ {

"keywords": [ "test", "fixture", "mocha", "testing", "jasmine" ],
"version": "1.0.0",
"version": "1.1.0",
"repository": {
"type": "git",
"url": "https://github.com/chaijs/chai-jquery://github.com/badunk/fixtures"
"url": "https://github.com/badunk/fixtures"
},
"bugs": {
"url": "https://github.com/chaijs/chai-jquery/issues://github.com/badunk/fixtures/issues"
"url": "https://github.com/badunk/fixtures/issues"
},

@@ -15,0 +15,0 @@ "main": "./fixtures",

@@ -6,4 +6,5 @@ describe("fixtures.Fixtures", function(){

var server = sinon.fakeServer.create();;
var fixturesContainer = function(){
return $('#' + fixtures.containerId);
var xhr = sinon.useFakeXMLHttpRequest();
var fixturesBody = function(){
return $('#' + fixtures.containerId).contents().find('body');
};

@@ -60,11 +61,11 @@ var appendFixturesContainerToDom = function(){

fixtures.load(fixtureUrl);
fixturesContainer().html().should.equal(ajaxData);
fixturesBody().html().should.equal(ajaxData);
});
it("should insert duplicated fixture HTML into container when the same url is provided twice in a single call", function(){
fixtures.load(fixtureUrl, fixtureUrl);
fixturesContainer().html().should.equal(ajaxData + ajaxData);
fixturesBody().html().should.equal(ajaxData + ajaxData);
});
it("should insert merged HTML of two fixtures into container when two different urls are provided in a single call", function(){
fixtures.load(fixtureUrl, anotherFixtureUrl);
fixturesContainer().html().should.equal(ajaxData + ajaxData);
fixturesBody().html().should.equal(ajaxData + ajaxData);
});

@@ -74,3 +75,3 @@ describe("when fixture container does not exist", function(){

fixtures.load(fixtureUrl);
fixturesContainer().size().should.equal(1);
fixturesBody().size().should.equal(1);
});

@@ -84,8 +85,8 @@ });

fixtures.load(fixtureUrl);
fixturesContainer().html().should.equal(ajaxData);
fixturesBody().html().should.equal(ajaxData);
});
});
describe("when fixture contains an inline &lt;script&gt; tag", function(){
xdescribe("when fixture contains an inline script tag", function(){
beforeEach(function(){
ajaxData = "<div><a id=\"anchor_01\"></a><script>$(function(){$('#anchor_01').addClass('foo')});</script></div>"
ajaxData = "<script>document.writeln('test')</script>"
server.respondWith(ajaxData);

@@ -95,3 +96,3 @@ });

fixtures.load(fixtureUrl);
$("#anchor_01").should.have.class('foo');
fixturesBody().html().should.equal('test');
});

@@ -107,15 +108,15 @@ });

fixtures.appendLoad(fixtureUrl);
fixturesContainer().html().should.equal(ajaxData);
fixturesBody().html().should.equal(ajaxData);
});
it("should insert duplicated fixture html into container when the same url is provided twice in a single call", function(){
fixtures.appendLoad(fixtureUrl, anotherFixtureUrl);
fixturesContainer().html().should.equal(ajaxData + ajaxData);
fixturesBody().html().should.equal(ajaxData + ajaxData);
});
it("should insert merged HTML of two fixtures into container when two different urls are provided in a single call", function(){
fixtures.appendLoad(fixtureUrl, anotherFixtureUrl);
fixturesContainer().html().should.equal(ajaxData + ajaxData);
fixturesBody().html().should.equal(ajaxData + ajaxData);
});
it("should automatically create fixtures container and append it to the DOM", function(){
fixtures.appendLoad(fixtureUrl);
fixturesContainer().size().should.equal(1);
fixturesBody().size().should.equal(1);
});

@@ -129,3 +130,3 @@ describe("with a prexisting fixture",function(){

fixtures.appendLoad(fixtureUrl);
fixturesContainer().html().should.equal(ajaxData + ajaxData);
fixturesBody().html().should.equal(ajaxData + ajaxData);
});

@@ -135,8 +136,8 @@

fixtures.appendLoad(fixtureUrl);
fixturesContainer().size().should.equal(1);
fixturesBody().size().should.equal(1);
});
});
describe("when fixture contains an inline &lt;script&gt; tag", function(){
describe("when fixture contains an inline script tag", function(){
beforeEach(function(){
ajaxData = "<div><a id=\"anchor_01\"></a><script>$(function(){ $('#anchor_01').addClass('foo')});</script></div>"
ajaxData = '<scr' + 'ipt>document.writeln("test");</scr' + 'ipt>';
server.respondWith(ajaxData);

@@ -147,3 +148,3 @@ });

fixtures.appendLoad(fixtureUrl);
$("#anchor_01").should.have.class('foo');
$.trim(fixturesBody().html()).should.equal('test');
})

@@ -178,14 +179,9 @@ });

fixtures.set(html);
fixturesContainer().html().should.equal(html);
fixturesBody().html().should.equal(html);
});
it("should insert jQuery element into container", function() {
fixtures.set($(html));
fixturesContainer().html().should.equal(html);
});
describe("when fixture container does not exist", function() {
it("should automatically create fixtures container and append it to DOM", function() {
fixtures.set(html);
fixturesContainer().size().should.equal(1);
fixturesBody().size().should.equal(1);
});

@@ -201,3 +197,3 @@ });

fixtures.set(html);
fixturesContainer().html().should.equal(html);
fixturesBody().html().should.equal(html);
});

@@ -211,14 +207,9 @@ });

fixtures.appendSet(html);
fixturesContainer().html().should.equal(html);
fixturesBody().html().should.equal(html);
});
it("should insert jQuery element into container", function() {
fixtures.appendSet($(html));
fixturesContainer().html().should.equal(html);
});
describe("when fixture container does not exist", function() {
it("should automatically create fixtures container and append it to DOM", function() {
fixtures.appendSet(html);
fixturesContainer().size().should.equal(1);
fixturesBody().size().should.equal(1);
});

@@ -234,3 +225,3 @@ });

fixtures.appendSet(html);
fixturesContainer().html().should.equal(html+html);
fixturesBody().html().should.equal(html+html);
});

@@ -240,29 +231,2 @@ });

describe("sandbox", function() {
describe("with no attributes parameter specified", function() {
it("should create DIV with id #sandbox", function() {
fixtures.sandbox().html().should.equal($('<div id="sandbox" />').html());
});
});
describe("with attributes parameter specified", function() {
it("should create DIV with attributes", function() {
var attributes = {
attr1: 'attr1 value',
attr2: 'attr2 value'
};
var element = $(fixtures.sandbox(attributes));
element.attr('attr1').should.equal(attributes.attr1);
element.attr('attr2').should.equal(attributes.attr2);
});
it("should be able to override id by setting it as attribute", function() {
var idOverride = 'overridden';
var element = $(fixtures.sandbox({id: idOverride}));
element.attr('id').should.equal(idOverride);
});
});
});
describe("cleanUp", function() {

@@ -272,3 +236,3 @@ it("should remove fixtures container from DOM", function() {

fixtures.cleanUp();
fixturesContainer().size().should.equal(0);
fixturesBody().size().should.equal(0);
});

@@ -278,3 +242,3 @@ });

describe("fixtures.Fixtures using real AJAX call", function() {
describe("fixtures.Fixtures using mock AJAX call", function() {
var defaultFixturesPath;

@@ -292,2 +256,14 @@

describe("when fixture file exists", function() {
var stub;
beforeEach(function(){
var xhr = sinon.useFakeXMLHttpRequest();
xhr.onCreate = function(xhr){
stub = sinon.stub(xhr, "send", function(something){
xhr.responseText = '<div id="real_non_mocked_fixture"></div>';
});
};
});
afterEach(function(){
stub.restore();
});
it("should load content of fixture file", function() {

@@ -294,0 +270,0 @@ var fixtureUrl = "real_non_mocked_fixture.html";

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc