Best JavaScript code snippet using ng-mocks
URI.js
Source:URI.js
1module("tinymce.util.URI");2test('protocol relative url', function() {3 var uri = new tinymce.util.URI('//www.site.com/dir1/file?query#hash');4 equal(uri.protocol, "");5 equal(uri.host, "www.site.com");6 equal(uri.path, "/dir1/file");7 equal(uri.query, "query");8 equal(uri.anchor, "hash");9 equal(uri.source, "//www.site.com/dir1/file?query#hash");10 equal(uri.getURI(), "//www.site.com/dir1/file?query#hash");11 equal(uri.toRelative('//www.site.com/dir1/file2'), 'file2');12 equal(uri.toRelative('//www.site2.com/dir1/file2'), '//www.site2.com/dir1/file2');13 equal(uri.toAbsolute('../file2'), '//www.site.com/dir1/file2');14 equal(uri.toAbsolute('//www.site2.com/dir1/file2'), '//www.site2.com/dir1/file2');15});16test('parseFullURLs', 3, function() {17 equal(new tinymce.util.URI('http://abc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash').getURI(), 'http://abc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash');18 ok(new tinymce.util.URI('http://a2bc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash').getURI() != 'http://abc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash');19 equal(new tinymce.util.URI('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890:8080/path/dir/file.ext?key1=val1&key2=val2#hash').getURI(), 'chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890:8080/path/dir/file.ext?key1=val1&key2=val2#hash');20});21test('relativeURLs', 31, function() {22 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/file.html').toRelative('http://www.site.com/dir1/dir3/file.html'), '../dir3/file.html');23 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/file.html').toRelative('http://www.site.com/dir3/dir4/file.html'), '../../dir3/dir4/file.html');24 equal(new tinymce.util.URI('http://www.site.com/dir1/').toRelative('http://www.site.com/dir1/dir3/file.htm'), 'dir3/file.htm');25 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('http://www.site2.com/dir1/dir3/file.htm'), 'http://www.site2.com/dir1/dir3/file.htm');26 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('http://www.site.com:8080/dir1/dir3/file.htm'), 'http://www.site.com:8080/dir1/dir3/file.htm');27 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('https://www.site.com/dir1/dir3/file.htm'), 'https://www.site.com/dir1/dir3/file.htm');28 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm'), '../../file.htm');29 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm?id=1#a'), '../../file.htm?id=1#a');30 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('mailto:test@test.com'), 'mailto:test@test.com');31 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('news:test'), 'news:test');32 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('javascript:void(0);'), 'javascript:void(0);');33 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('about:blank'), 'about:blank');34 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('#test'), '#test');35 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('test.htm'), 'test.htm');36 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('http://www.site.com/dir1/dir2/test.htm'), 'test.htm');37 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('dir2/test.htm'), 'dir2/test.htm');38 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('../dir2/test.htm'), 'test.htm');39 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('../dir3/'), '../dir3/');40 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('../../../../../../test.htm'), '../../test.htm');41 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('//www.site.com/test.htm'), '../../test.htm');42 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('@@tinymce'), '@@tinymce'); // Zope 3 URL43 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('../@@tinymce'), '../@@tinymce'); // Zope 3 URL44 equal(new tinymce.util.URI('http://www.site.com/').toRelative('dir2/test.htm'), 'dir2/test.htm');45 equal(new tinymce.util.URI('http://www.site.com/').toRelative('./'), './');46 equal(new tinymce.util.URI('http://www.site.com/test/').toRelative('../'), '../');47 equal(new tinymce.util.URI('http://www.site.com/test/test/').toRelative('../'), '../');48 equal(new tinymce.util.URI('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890/dir1/dir2/').toRelative('/dir1', true), '../');49 equal(new tinymce.util.URI('http://www.site.com/').toRelative('http://www.site.com/'), 'http://www.site.com/');50 equal(new tinymce.util.URI('http://www.site.com/').toRelative('http://www.site.com'), 'http://www.site.com/');51 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm?q=http://site.com/'), '../../file.htm?q=http://site.com/');52 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm#http://site.com/'), '../../file.htm#http://site.com/');53});54test('absoluteURLs', 19, function() {55 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute(''), 'http://www.site.com/dir1/dir2/');56 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('../dir3'), 'http://www.site.com/dir1/dir3');57 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('../dir3', 1), '/dir1/dir3');58 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('../../../../dir3'), 'http://www.site.com/dir3');59 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('../abc/def/../../abc/../dir3/file.htm'), 'http://www.site.com/dir1/dir3/file.htm');60 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('http://www.site.com/dir2/dir3'), 'http://www.site.com/dir2/dir3');61 equal(new tinymce.util.URI('http://www.site2.com/dir1/dir2/').toAbsolute('http://www.site2.com/dir2/dir3'), 'http://www.site2.com/dir2/dir3');62 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('mailto:test@test.com'), 'mailto:test@test.com');63 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('news:test'), 'news:test');64 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('javascript:void(0);'), 'javascript:void(0);');65 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('about:blank'), 'about:blank');66 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('#test'), '#test');67 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('test.htm'), 'http://www.site.com/dir1/dir2/test.htm');68 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('../@@tinymce'), 'http://www.site.com/dir1/@@tinymce'); // Zope 3 URL69 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').getURI(), 'http://www.site.com/dir1/dir2/');70 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('/dir1/dir1/'), 'http://www.site.com/dir1/dir1/');71 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('https://www.site.com/dir1/dir2/', true), 'https://www.site.com/dir1/dir2/');72 equal(new tinymce.util.URI('http://www.site.com/dir1/dir2/').toAbsolute('http://www.site.com/dir1/dir2/', true), '/dir1/dir2/');73 equal(new tinymce.util.URI('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890/dir1/dir2/').toAbsolute('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890/dir1/dir2/', true), '/dir1/dir2/');74});75test('strangeURLs', 6, function() {76 equal(new tinymce.util.URI('//www.site.com').getURI(), '//www.site.com');77 equal(new tinymce.util.URI('mailto:test@test.com').getURI(), 'mailto:test@test.com');78 equal(new tinymce.util.URI('news:somegroup').getURI(), 'news:somegroup');79 equal(new tinymce.util.URI('skype:somegroup').getURI(), 'skype:somegroup');80 equal(new tinymce.util.URI('tel:somegroup').getURI(), 'tel:somegroup');81 equal(new tinymce.util.URI('//www.site.com/a@b').getURI(), '//www.site.com/a@b');82});83test('isSameOrigin', function() {84 ok(new tinymce.util.URI('http://www.site.com').isSameOrigin(new tinymce.util.URI('http://www.site.com')));85 ok(new tinymce.util.URI('//www.site.com').isSameOrigin(new tinymce.util.URI('//www.site.com')));86 ok(new tinymce.util.URI('http://www.site.com:80').isSameOrigin(new tinymce.util.URI('http://www.site.com')));87 ok(new tinymce.util.URI('https://www.site.com:443').isSameOrigin(new tinymce.util.URI('https://www.site.com')));88 ok(new tinymce.util.URI('//www.site.com:80').isSameOrigin(new tinymce.util.URI('//www.site.com:80')));89 ok(new tinymce.util.URI('mailto:test@site.com').isSameOrigin(new tinymce.util.URI('mailto:test@site.com')));90 ok(new tinymce.util.URI('mailto:test@site.com:25').isSameOrigin(new tinymce.util.URI('mailto:test@site.com')));91 ok(new tinymce.util.URI('ftp://www.site.com').isSameOrigin(new tinymce.util.URI('ftp://www.site.com')));92 ok(new tinymce.util.URI('ftp://www.site.com:21').isSameOrigin(new tinymce.util.URI('ftp://www.site.com')));93 ok(new tinymce.util.URI('https://www.site.com').isSameOrigin(new tinymce.util.URI('http://www.site.com')) == false);94 ok(new tinymce.util.URI('http://www.site.com:8080').isSameOrigin(new tinymce.util.URI('http://www.site.com')) == false);95 ok(new tinymce.util.URI('https://www.site.com:8080').isSameOrigin(new tinymce.util.URI('https://www.site.com')) == false);96 ok(new tinymce.util.URI('ftp://www.site.com:1021').isSameOrigin(new tinymce.util.URI('ftp://www.site.com')) == false);97});98test('getDocumentBaseUrl', function() {99 var getDocumentBaseUrl = tinymce.util.URI.getDocumentBaseUrl;100 equal(getDocumentBaseUrl({protocol: 'file:', host: '', pathname: '/dir/path1/path2'}), 'file:///dir/path1/');101 equal(getDocumentBaseUrl({protocol: 'http:', host: 'localhost', pathname: '/dir/path1/path2'}), 'http://localhost/dir/path1/');102 equal(getDocumentBaseUrl({protocol: 'https:', host: 'localhost', pathname: '/dir/path1/path2'}), 'https://localhost/dir/path1/');103 equal(getDocumentBaseUrl({protocol: 'https:', host: 'localhost', pathname: '/dir/path1/path2/'}), 'https://localhost/dir/path1/path2/');104 equal(getDocumentBaseUrl({protocol: 'http:', host: 'localhost:8080', pathname: '/dir/path1/path2'}), 'http://localhost:8080/dir/path1/');105 equal(getDocumentBaseUrl({protocol: 'http:', host: 'localhost', pathname: '/dir/path1/path2/file.html'}), 'http://localhost/dir/path1/path2/');106 equal(getDocumentBaseUrl({protocol: 'http:', host: 'localhost', pathname: '/'}), 'http://localhost/');107 equal(getDocumentBaseUrl({protocol: 'applewebdata:', href: 'applewebdata://something//dir/path1#hash'}), 'applewebdata://something//dir/');108 equal(getDocumentBaseUrl({protocol: 'applewebdata:', href: 'applewebdata://something//dir/path1'}), 'applewebdata://something//dir/');...
test.js
Source:test.js
1/**2 * Copyright (c) 2014, CKSource - Frederico Knabben. All rights reserved.3 * Licensed under the terms of the MIT License (see LICENSE.md).4 */5'use strict';6/*global describe, it */7/*jshint -W030 */8/* removes annoying warning caused by some of Chai's assertions */9var expect = require( 'chai' ).expect,10 path = require( 'path' ),11 gerard = require( '../' );12function normalize( arg ) {13 if ( Array.isArray( arg ) ) {14 return arg.map( normalize ).sort();15 } else if ( typeof arg == 'string' ) {16 return path.normalize( arg );17 } else {18 return arg;19 }20}21describe( 'Gerard', function() {22 var dir1 = path.normalize( 'test/dir1' ),23 testDir = path.normalize( 'test/' ),24 invalid = path.normalize( 'invalid/path' );25 describe( 'with a directory', function() {26 it( 'should pass an error if invalid path was given', function( done ) {27 gerard( invalid, function( err, results ) {28 expect( err ).to.exist;29 expect( err.code ).to.equal( 'ENOENT' );30 expect( results ).to.not.exist;31 done();32 } );33 } );34 it( 'should list all the files in the directory', function( done ) {35 var expected = [36 'test/dir1/a.js',37 'test/dir1/b.js',38 'test/dir1/dir3/c.js',39 'test/dir1/dir3/d.js',40 'test/dir1/dir3/dir2/dir4/h.js',41 'test/dir1/dir3/dir2/e.js',42 'test/dir1/dir3/dir2/f.js',43 'test/dir1/dir3/dir2/g.js',44 'test/dir1/dir3/test.txt',45 'test/dir1/test.txt'46 ];47 gerard( dir1, function( err, results ) {48 expect( err ).to.not.exist;49 expect( results ).to.be.an( 'array' );50 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );51 done();52 } );53 } );54 it( 'should handle "ignore" option', function( done ) {55 var expected = [56 'test/dir1/dir3/test.txt',57 'test/dir1/test.txt',58 'test/dir2/dir3/test.txt',59 'test/dir2/test.txt',60 'test/dir3/test.txt'61 ];62 gerard( testDir, {63 ignore: '**/*.js'64 }, function( err, results ) {65 expect( err ).to.not.exist;66 expect( results ).to.be.an( 'array' );67 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );68 done();69 } );70 } );71 it( 'should handle array of ignore patterns"', function( done ) {72 var expected = [73 'test/dir1/dir3/test.txt',74 'test/dir1/test.txt',75 'test/dir3/test.txt'76 ];77 gerard( testDir, {78 ignore: [79 '**/*.js',80 '**/dir2/**'81 ]82 }, function( err, results ) {83 expect( err ).to.not.exist;84 expect( results ).to.be.an( 'array' );85 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );86 done();87 } );88 } );89 it( 'should handle "stats" option', function( done ) {90 gerard( dir1, {91 stats: true92 }, function( err, results ) {93 expect( err ).to.not.exist;94 expect( results ).to.be.an( 'array' );95 expect( results ).to.have.length( 10 );96 results.forEach( function( result ) {97 expect( result ).to.be.an( 'object' );98 expect( result ).to.contain.keys( [ 'name', 'dir', 'path', 'stats' ] );99 } );100 done();101 } );102 } );103 it( 'should produce unique results only', function( done ) {104 var expected = [105 'test/dir1/a.js',106 'test/dir1/b.js',107 'test/dir1/dir3/c.js',108 'test/dir1/dir3/d.js',109 'test/dir1/dir3/dir2/dir4/h.js',110 'test/dir1/dir3/dir2/e.js',111 'test/dir1/dir3/dir2/f.js',112 'test/dir1/dir3/dir2/g.js',113 'test/dir1/dir3/test.txt',114 'test/dir1/test.txt',115 'test/dir2/a.js',116 'test/dir2/b.js',117 'test/dir2/dir3/c.js',118 'test/dir2/dir3/d.js',119 'test/dir2/dir3/dir2/dir4/h.js',120 'test/dir2/dir3/dir2/e.js',121 'test/dir2/dir3/dir2/f.js',122 'test/dir2/dir3/dir2/g.js',123 'test/dir2/dir3/test.txt',124 'test/dir2/test.txt',125 'test/dir3/c.js',126 'test/dir3/d.js',127 'test/dir3/dir2/dir4/h.js',128 'test/dir3/dir2/e.js',129 'test/dir3/dir2/f.js',130 'test/dir3/dir2/g.js',131 'test/dir3/test.txt',132 'test/test.js'133 ];134 gerard( [ dir1, testDir ], function( err, results ) {135 expect( err ).to.not.exist;136 expect( results ).to.be.an( 'array' );137 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );138 done();139 } );140 } );141 } );142 describe( 'with a pattern', function() {143 it( 'should handle test/dir1/**', function( done ) {144 var expected = [145 'test/dir1/a.js',146 'test/dir1/b.js',147 'test/dir1/test.txt',148 'test/dir1/dir3/c.js',149 'test/dir1/dir3/d.js',150 'test/dir1/dir3/test.txt',151 'test/dir1/dir3/dir2/f.js',152 'test/dir1/dir3/dir2/e.js',153 'test/dir1/dir3/dir2/g.js',154 'test/dir1/dir3/dir2/dir4/h.js'155 ];156 gerard( 'test/dir1/**', function( err, results ) {157 expect( err ).to.not.exist;158 expect( results ).to.be.an( 'array' );159 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );160 done();161 } );162 } );163 it( 'should handle test/**/test.txt', function( done ) {164 var expected = [165 'test/dir1/test.txt',166 'test/dir1/dir3/test.txt',167 'test/dir2/test.txt',168 'test/dir2/dir3/test.txt',169 'test/dir3/test.txt'170 ];171 gerard( 'test/**/test.txt', function( err, results ) {172 expect( err ).to.not.exist;173 expect( results ).to.be.an( 'array' );174 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );175 done();176 } );177 } );178 it( 'should handle test/**/*.js', function( done ) {179 var expected = [180 'test/dir1/a.js',181 'test/dir1/b.js',182 'test/dir1/dir3/c.js',183 'test/dir1/dir3/d.js',184 'test/dir1/dir3/dir2/dir4/h.js',185 'test/dir1/dir3/dir2/e.js',186 'test/dir1/dir3/dir2/f.js',187 'test/dir1/dir3/dir2/g.js',188 'test/dir2/a.js',189 'test/dir2/b.js',190 'test/dir2/dir3/c.js',191 'test/dir2/dir3/d.js',192 'test/dir2/dir3/dir2/dir4/h.js',193 'test/dir2/dir3/dir2/e.js',194 'test/dir2/dir3/dir2/f.js',195 'test/dir2/dir3/dir2/g.js',196 'test/dir3/c.js',197 'test/dir3/d.js',198 'test/dir3/dir2/dir4/h.js',199 'test/dir3/dir2/e.js',200 'test/dir3/dir2/f.js',201 'test/dir3/dir2/g.js',202 'test/test.js'203 ];204 gerard( 'test/**/*.js', function( err, results ) {205 expect( err ).to.not.exist;206 expect( results ).to.be.an( 'array' );207 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );208 done();209 } );210 } );211 it( 'should handle test/dir2/*/*.js', function( done ) {212 var expected = [213 'test/dir2/dir3/c.js',214 'test/dir2/dir3/d.js'215 ];216 gerard( 'test/dir2/*/*.js', function( err, results ) {217 expect( err ).to.not.exist;218 expect( results ).to.be.an( 'array' );219 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );220 done();221 } );222 } );223 it( 'should handle test/*/dir3/*.js', function( done ) {224 var expected = [225 'test/dir1/dir3/c.js',226 'test/dir1/dir3/d.js',227 'test/dir2/dir3/c.js',228 'test/dir2/dir3/d.js'229 ];230 gerard( 'test/*/dir3/*.js', function( err, results ) {231 expect( err ).to.not.exist;232 expect( results ).to.be.an( 'array' );233 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );234 done();235 } );236 } );237 it( 'should handle test/*/dir3/test.txt', function( done ) {238 var expected = [239 'test/dir1/dir3/test.txt',240 'test/dir2/dir3/test.txt'241 ];242 gerard( 'test/*/dir3/test.txt', function( err, results ) {243 expect( err ).to.not.exist;244 expect( results ).to.be.an( 'array' );245 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );246 done();247 } );248 } );249 it( 'should handle */*.js', function( done ) {250 var expected = [ 'test/test.js' ];251 gerard( '*/*.js', function( err, results ) {252 expect( err ).to.not.exist;253 expect( results ).to.be.an( 'array' );254 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );255 done();256 } );257 } );258 it( 'should handle the stats option', function( done ) {259 gerard( 'test/**/*.txt', {260 stats: true261 }, function( err, results ) {262 expect( err ).to.not.exist;263 expect( results ).to.be.an( 'array' );264 expect( results ).to.have.length( 5 );265 results.forEach( function( result ) {266 expect( result ).to.be.an( 'object' );267 expect( result ).to.contain.keys( [ 'name', 'dir', 'path', 'stats' ] );268 } );269 done();270 } );271 } );272 it( 'should handle the ignore option', function( done ) {273 var expected = [ 'test/dir1/dir3/test.txt',274 'test/dir1/test.txt',275 'test/dir2/dir3/test.txt',276 'test/dir2/test.txt',277 'test/dir3/test.txt'278 ];279 gerard( 'test/**', {280 ignore: '**/*.js',281 stats: false282 }, function( err, results ) {283 expect( err ).to.not.exist;284 expect( results ).to.be.an( 'array' );285 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );286 done();287 } );288 } );289 it( 'should handle multiple patterns', function( done ) {290 var expected = [291 'test/dir1/dir3/c.js',292 'test/dir1/dir3/d.js',293 'test/dir2/dir3/c.js',294 'test/dir2/dir3/d.js'295 ];296 gerard( [297 'test/dir1/*/*.js',298 'test/dir2/*/*.js'299 ], function( err, results ) {300 expect( err ).to.not.exist;301 expect( results ).to.be.an( 'array' );302 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );303 done();304 } );305 } );306 it( 'should produce unique results only', function( done ) {307 var expected = [308 'test/dir1/a.js',309 'test/dir1/b.js',310 'test/dir1/dir3/c.js',311 'test/dir1/dir3/d.js',312 'test/dir1/dir3/dir2/dir4/h.js',313 'test/dir1/dir3/dir2/e.js',314 'test/dir1/dir3/dir2/f.js',315 'test/dir1/dir3/dir2/g.js',316 'test/dir2/dir3/c.js',317 'test/dir2/dir3/d.js',318 'test/dir3/c.js',319 'test/dir3/d.js'320 ];321 gerard( [322 'test/dir1/**/*.js',323 'test/**/dir3/*.js'324 ], function( err, results ) {325 expect( err ).to.not.exist;326 expect( results ).to.be.an( 'array' );327 expect( normalize( results ) ).to.deep.equal( normalize( expected ) );328 done();329 } );330 } );331 it( 'should return empty array if no matches', function( done ) {332 gerard( 'test/**/foo/**', function( err, results ) {333 expect( err ).to.not.exist;334 expect( results ).to.be.an( 'array' );335 expect( results ).to.be.empty;336 done();337 } );338 } );339 } );...
Using AI Code Generation
1import {dir2} from 'ng-mocks';2describe('MyComponent', () => {3 let component: MyComponent;4 let fixture: ComponentFixture<MyComponent>;5 beforeEach(async(() => {6 TestBed.configureTestingModule({7 imports: [NgxChartsModule]8 }).compileComponents();9 }));10 beforeEach(() => {11 fixture = TestBed.createComponent(MyComponent);12 component = fixture.componentInstance;13 fixture.detectChanges();14 });15 it('should create', () => {16 expect(component).toBeTruthy();17 });18 it('should have 3 series', () => {19 const series = dir2(fixture, 'g.series');20 expect(series.length).toBe(3);21 });22});23const series = dir2(fixture, 'g.series');24const firstSeries = series[0];25const firstSeries = fixture.debugElement.query(By.css('g.series'));
Using AI Code Generation
1import { dir2 } from 'ng-mocks';2import { dir2 } from 'ng-mocks';3import { dir2 } from 'ng-mocks';4import { dir2 } from 'ng-mocks';5import { dir2 } from 'ng-mocks';6import { dir2 } from 'ng-mocks';7import { dir2 } from 'ng-mocks';8import { dir2 } from 'ng-mocks';9import { dir2 } from 'ng-mocks';10import { dir2 } from 'ng-mocks';11import { dir2 } from 'ng-mocks';12import { dir2 } from 'ng-mocks';13import { dir2 } from 'ng-mocks';14import { dir2 } from 'ng-mocks';15import { dir2 } from 'ng-mocks';16import { dir2 } from 'ng-mocks';17import { dir2 } from 'ng-mocks';18import { dir2 } from 'ng-mocks';19import { dir2 } from 'ng-mocks';20import { dir2 } from 'ng
Using AI Code Generation
1import { dir2 } from 'ng-mocks';2import { dir2 } from 'ng-mocks';3import { dir2 } from 'ng-mocks';4import { dir2 } from 'ng-mocks';5import { dir2 } from 'ng-mocks';6import { dir2 } from 'ng-mocks';7import { dir2 } from 'ng-mocks';8import { dir2 } from 'ng-mocks';9import { dir2 } from 'ng-mocks';10import { dir2 } from 'ng-mocks';11import { dir2 } from 'ng-mocks';12import { dir2 } from 'ng-mocks';13import { dir2 } from '
Using AI Code Generation
1var ngMocks = require('ng-mocks');2ngMocks.dir2('app');3var ngMocks = require('ng-mocks');4ngMocks.dir2('app');5var ngMocks = require('ng-mocks');6ngMocks.dir2('app');7var ngMocks = require('ng-mocks');8ngMocks.dir2('app');9var ngMocks = require('ng-mocks');10ngMocks.dir2('app');11var ngMocks = require('ng-mocks');12ngMocks.dir2('app');13var ngMocks = require('ng-mocks');14ngMocks.dir2('app');15var ngMocks = require('ng-mocks');16ngMocks.dir2('app');17var ngMocks = require('ng-mocks');18ngMocks.dir2('app');19var ngMocks = require('ng-mocks');20ngMocks.dir2('app');21var ngMocks = require('ng-mocks');22ngMocks.dir2('app');23var ngMocks = require('ng-mocks');24ngMocks.dir2('app');25var ngMocks = require('ng-mocks');26ngMocks.dir2('app');27var ngMocks = require('ng-mocks');28ngMocks.dir2('app');29var ngMocks = require('ng-mocks');30ngMocks.dir2('app');31var ngMocks = require('ng-mocks');32ngMocks.dir2('app');
Using AI Code Generation
1import { dir2 } from 'ng-mocks';2import { AppModule } from 'src/app/app.module';3import { TestModule } from 'src/app/test/test.module';4describe('TestModule', () => {5 it('should have the correct imports', () => {6 expect(dir2(TestModule)).toEqual([AppModule]);7 });8});9dir2() is a method of ng-mocks
Using AI Code Generation
1var dir2 = require('ng-mocks').dir2;2var dir2 = require('ng-mocks').dir2;3describe('Test', function() {4 var $componentController, $rootScope, $scope, $compile, $templateCache;5 beforeEach(module('testApp'));6 beforeEach(inject(function(_$componentController_, _$rootScope_, _$compile_, _$templateCache_) {7 $componentController = _$componentController_;8 $rootScope = _$rootScope_;9 $scope = $rootScope.$new();10 $compile = _$compile_;11 $templateCache = _$templateCache_;12 }));13 it('should render the template', function() {14 $templateCache.put('test.html', '<div>test</div>');15 var ctrl = $componentController('test', {$scope: $scope});16 var element = $compile('<test></test>')($scope);17 $scope.$digest();18 var dir = dir2(element);19 expect(dir.template).toBe('<div>test</div>');20 });21});22$componentController('test', {$scope: $scope}, {template: '<div>test</div>'});23$componentController('test', {$scope: $scope}, {templateUrl: 'test.html'});
Using AI Code Generation
1import { dir2 } from 'ng-mocks';2const fixture = TestBed.createComponent(MyComponent);3const component = fixture.componentInstance;4const debugElement = fixture.debugElement;5const directive = dir2(debugElement, MyDirective);6const directiveInstance = directive.injector.get(MyDirective);7const element = directive.nativeElement;8const componentInstance = directive.componentInstance;9const template = directive.template;10const view = directive.view;11const viewContainer = directive.viewContainer;12const viewContainerElement = directive.viewContainerElement;13const viewContainerElementNative = directive.viewContainerElementNative;14const viewContainerElementTemplate = directive.viewContainerElementTemplate;15const viewContainerElementView = directive.viewContainerElementView;16const viewContainerElementViewContainer = directive.viewContainerElementViewContainer;17import { dir2 } from 'ng-mocks';18const fixture = TestBed.createComponent(MyComponent);19const component = fixture.componentInstance;20const debugElement = fixture.debugElement;21const directive = dir2(debugElement, MyDirective);22const directiveInstance = directive.injector.get(MyDirective);23const element = directive.nativeElement;24const componentInstance = directive.componentInstance;25const template = directive.template;26const view = directive.view;27const viewContainer = directive.viewContainer;28const viewContainerElement = directive.viewContainerElement;29const viewContainerElementNative = directive.viewContainerElementNative;30const viewContainerElementTemplate = directive.viewContainerElementTemplate;31const viewContainerElementView = directive.viewContainerElementView;
Using AI Code Generation
1import { dir2 } from 'ng-mocks';2const dir1 = dir2({3});4const dir2 = dir2({5});6const dir3 = dir2({7});8describe('dir1', () => {9 it('should have dir2', () => {10 const fixture = TestBed.configureTestingModule({11 }).createComponent(dir1);12 fixture.detectChanges();13 const instance = fixture.debugElement.children[0].injector.get(dir1);14 expect(instance.dir2).toBeDefined();15 });16});17const dir1 = dir2({18});19const dir2 = dir2({20});21const dir3 = dir2({22});23describe('dir1', () => {24 it('should have dir2', () => {25 const fixture = TestBed.configureTestingModule({26 }).createComponent(dir1);27 fixture.detectChanges();28 const instance = fixture.debugElement.children[0].injector.get(dir1);29 expect(instance.dir2).toBeDefined();30 });31});32const dir1 = dir2({33});34const dir2 = dir2({35});36const dir3 = dir2({37});38describe('dir1', () => {39 it('
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!