How to use typeTests method in Jest

Best JavaScript code snippet using jest

ComparisonChart.spec.js

Source:ComparisonChart.spec.js Github

copy

Full Screen

1import { shallowMount } from "@vue/test-utils";2import ComparisonChart from "@/components/Comparison/ComparisonChart.vue";3describe("ComparisonChart.vue", () => {4 const wrapper = shallowMount(ComparisonChart, {5 methods: {6 // replacing createChart() method because of mounted lifecycle7 createChart: jest.fn(),8 },9 });10 it("should renders correct text from parameters - returnThInterestOrClientRate", () => {11 expect(wrapper.vm.returnThInterestOrClientRate(4)).toBe("% Clientes");12 expect(wrapper.vm.returnThInterestOrClientRate(5)).toBe("Juros");13 expect(wrapper.vm.returnThInterestOrClientRate(2)).toBe("% Clientes");14 expect(wrapper.vm.returnThInterestOrClientRate(3)).toBe("Juros");15 });16 it("should renders correct text from parameters - getIndexerText", () => {17 const cdi = "FLUTUANTES_CDI";18 const prefix = "PRE_FIXADO";19 const interestRate1 = { rate: 0.089, referentialRateIndexer: cdi };20 const interestRate2 = { rate: 1.0, referentialRateIndexer: cdi };21 const interestRate3 = { rate: "NA", referentialRateIndexer: prefix };22 expect(wrapper.vm.getIndexerText(interestRate1)).toBe(23 " - FLUTUANTES_CDI / 8%"24 );25 expect(wrapper.vm.getIndexerText(interestRate2)).toBe(26 " - FLUTUANTES_CDI / 100%"27 );28 expect(wrapper.vm.getIndexerText(interestRate3)).toBe(" - " + prefix);29 });30 it("should return proper response to companyColors calls - companyColors", () => {31 const nameAndIndexerType = "Company Test";32 const whiteColor = "#FFFFFF";33 const objColorMap = {34 nameAndIndexerType,35 backgroundColor: whiteColor,36 borderColor: whiteColor,37 };38 const colorMap = [objColorMap];39 const typeTests = [40 wrapper.vm.companyColors(nameAndIndexerType, 1, colorMap),41 wrapper.vm.companyColors("Another Company", 1, colorMap),42 wrapper.vm.companyColors(nameAndIndexerType, 2, colorMap),43 ];44 expect(typeTests[0].backgroundColor).toBe(whiteColor);45 expect(typeTests[0].borderColor).toBe(whiteColor);46 expect(typeTests[1]).toBe(undefined);47 expect(typeTests[2].backgroundColor === whiteColor).toBeFalsy();48 expect(typeTests[2].borderColor === whiteColor).toBeFalsy();49 });50 it("should return proper response to participantCreditData calls - participantCreditData", () => {51 const creditDatas = [52 [53 { type: "loan", someValue: "1" },54 { type: "financing", someValue: "1" },55 ],56 [57 { type: "financing", someValue: "2" },58 { type: "loan", someValue: "2" },59 ],60 [61 { type: "financing", someValue: "3" },62 { type: "loan", someValue: "3" },63 ],64 [65 { type: "loan", someValue: "3" },66 { type: "financing", someValue: "3" },67 ],68 [69 { type: "loan", someValue: "4" },70 { type: "financing", someValue: "4" },71 ],72 ];73 const participant1 = {74 participantCreditData: creditDatas[0],75 participantId: "1",76 };77 const participant2 = {78 participantCreditData: creditDatas[1],79 participantId: "2",80 };81 const participant3 = {82 participantCreditData: creditDatas[2],83 participantId: "3",84 };85 const participant4 = {86 participantCreditData: creditDatas[3],87 participantId: "4",88 };89 const participant5 = {90 participantCreditData: creditDatas[4],91 participantId: "5",92 };93 const participants = [94 participant1,95 participant2,96 participant3,97 participant4,98 ];99 const creditTypes = ["loan", "financing", "other"];100 const typeTests = [101 wrapper.vm.participantCreditData(102 participant1,103 participants,104 creditTypes[0]105 ),106 wrapper.vm.participantCreditData(107 participant2,108 participants,109 creditTypes[1]110 ),111 wrapper.vm.participantCreditData(112 participant3,113 participants,114 creditTypes[2]115 ),116 wrapper.vm.participantCreditData(117 participant4,118 participants,119 creditTypes[0]120 ),121 wrapper.vm.participantCreditData(122 participant5,123 participants,124 creditTypes[0]125 ),126 ];127 expect(typeTests[0]).toBe(creditDatas[0][0]);128 expect(typeTests[1]).toBe(creditDatas[1][0]);129 expect(typeTests[2]).toBe(undefined);130 expect(typeTests[3]).toBe(creditDatas[3][0]);131 expect(typeTests[4]).toBe(undefined);132 });133 it("should return correct data - getParticipantChartData", () => {134 const interestRate = {135 referentialRateIndexer: "PRE_FIXADO",136 rate: "N/A",137 applications: [138 {139 interval: "1_FAIXA",140 indexer: { rate: "0.03" },141 customers: { rate: "0.0020" },142 },143 {144 interval: "2_FAIXA",145 indexer: { rate: "0.07" },146 customers: { rate: "0.0030" },147 },148 {149 interval: "3_FAIXA",150 indexer: { rate: "0.075" },151 customers: { rate: "0.25" },152 },153 {154 interval: "4_FAIXA",155 indexer: { rate: "0.1350" },156 customers: { rate: "0.7450" },157 },158 ],159 minimumRate: "0.003",160 maximumRate: "0.1399",161 };162 const expectedIndexer = ["0.30", "3.00", "7.00", "7.50", "13.50", "13.99"];163 const expectedCustomers = [164 "0.00",165 "0.20",166 "0.30",167 "25.00",168 "74.50",169 "0.00",170 ];171 const resultIndexer = wrapper.vm.getParticipantChartData(172 interestRate,173 "indexer"174 );175 const resultCustomers = wrapper.vm.getParticipantChartData(176 interestRate,177 "customers"178 );179 for (let i = 0; i < expectedIndexer.length; i++) {180 expect(resultIndexer[i]).toBe(expectedIndexer[i]);181 }182 for (let i = 0; i < expectedCustomers.length; i++) {183 expect(resultCustomers[i]).toBe(expectedCustomers[i]);184 }185 });186 it("should return correct data - getDataSetCustomers", () => {187 const label = "Label 1";188 const interestRate = {189 referentialRateIndexer: "PRE_FIXADO",190 rate: "N/A",191 applications: [192 {193 interval: "1_FAIXA",194 indexer: { rate: "0.03" },195 customers: { rate: "0.0020" },196 },197 {198 interval: "2_FAIXA",199 indexer: { rate: "0.07" },200 customers: { rate: "0.0030" },201 },202 {203 interval: "3_FAIXA",204 indexer: { rate: "0.075" },205 customers: { rate: "0.25" },206 },207 {208 interval: "4_FAIXA",209 indexer: { rate: "0.1350" },210 customers: { rate: "0.7450" },211 },212 ],213 minimumRate: "0.003",214 maximumRate: "0.1399",215 };216 const companyColors = { backgroundColor: "blue", borderColor: "red" };217 const result = wrapper.vm.getDataSetCustomers(218 label,219 interestRate,220 companyColors221 );222 expect(result.label).toBe(label);223 expect(result.type).toBe("bar");224 expect(result.order).toBe(2);225 expect(result.yAxisID).toBe("customers");226 expect(result.backgroundColor).toBe("blue");227 expect(result.borderColor).toBe(undefined);228 });229 it("should return correct data - getDataSetInterest", () => {230 const label = "Label 1";231 const interestRate = {232 referentialRateIndexer: "PRE_FIXADO",233 rate: "N/A",234 applications: [235 {236 interval: "1_FAIXA",237 indexer: { rate: "0.03" },238 customers: { rate: "0.0020" },239 },240 {241 interval: "2_FAIXA",242 indexer: { rate: "0.07" },243 customers: { rate: "0.0030" },244 },245 {246 interval: "3_FAIXA",247 indexer: { rate: "0.075" },248 customers: { rate: "0.25" },249 },250 {251 interval: "4_FAIXA",252 indexer: { rate: "0.1350" },253 customers: { rate: "0.7450" },254 },255 ],256 minimumRate: "0.003",257 maximumRate: "0.1399",258 };259 const companyColors = { backgroundColor: "blue", borderColor: "red" };260 const result = wrapper.vm.getDataSetInterest(261 label,262 interestRate,263 companyColors264 );265 expect(result.label).toBe(label);266 expect(result.type).toBe("line");267 expect(result.order).toBe(1);268 expect(result.yAxisID).toBe("interest");269 expect(result.backgroundColor).toBe("blue");270 expect(result.borderColor).toBe("red");271 });272 it("should return correct data - fillDataSets", () => {273 const participantData = { companyName: "Test Company" };274 const interestRate = {275 referentialRateIndexer: "PRE_FIXADO",276 rate: "N/A",277 applications: [278 {279 interval: "1_FAIXA",280 indexer: { rate: "0.03" },281 customers: { rate: "0.0020" },282 },283 {284 interval: "2_FAIXA",285 indexer: { rate: "0.07" },286 customers: { rate: "0.0030" },287 },288 {289 interval: "3_FAIXA",290 indexer: { rate: "0.075" },291 customers: { rate: "0.25" },292 },293 {294 interval: "4_FAIXA",295 indexer: { rate: "0.1350" },296 customers: { rate: "0.7450" },297 },298 ],299 minimumRate: "0.003",300 maximumRate: "0.1399",301 };302 const colorMap = [303 {304 nameAndIndexerType: participantData.companyName,305 backgroundColor: "whiteColor",306 borderColor: "whiteColor",307 },308 ];309 let dataSets = wrapper.vm.fillDataSets(310 [],311 participantData,312 interestRate,313 1,314 colorMap315 );316 expect(dataSets).toBeDefined();317 });...

Full Screen

Full Screen

consent-document.integration.js

Source:consent-document.integration.js Github

copy

Full Screen

1/* global describe,before,it */2'use strict';3process.env.NODE_ENV = 'test';4const _ = require('lodash');5const constNames = require('../models/const-names');6const SharedIntegration = require('./util/shared-integration');7const RRSuperTest = require('./util/rr-super-test');8const Generator = require('./util/generator');9const ConsentDocumentHistory = require('./util/consent-document-history');10const config = require('../config');11const consentTypeCommon = require('./util/consent-type-common');12const consentDocumentCommon = require('./util/consent-document-common');13describe('consent document integration', function consentDocumentIntegration() {14 const userCount = 4;15 const documentCount = 9;16 const rrSuperTest = new RRSuperTest();17 const generator = new Generator();18 const shared = new SharedIntegration(rrSuperTest, generator);19 const history = new ConsentDocumentHistory(userCount);20 const typeTests = new consentTypeCommon.IntegrationTests(rrSuperTest, {21 generator, hxConsentType: history.hxType,22 });23 const tests = new consentDocumentCommon.IntegrationTests(rrSuperTest, {24 generator, hxConsentDocument: history,25 });26 before(shared.setUpFn());27 it('login as super', shared.loginFn(config.superUser));28 const roles = [null, ...constNames.consentRoles];29 _.range(documentCount).forEach((index) => {30 const options = { role: roles[index % 3] };31 it(`create consent type ${index}`,32 typeTests.createConsentTypeFn(options));33 it(`add translated (es) consent type ${index}`,34 typeTests.translateConsentTypeFn(index, 'es'));35 });36 it('logout as super', shared.logoutFn());37 _.range(documentCount).forEach((index) => {38 it('login as super', shared.loginFn(config.superUser));39 it(`create consent document of type ${index}`,40 tests.createConsentDocumentFn(index));41 it('logout as super', shared.logoutFn());42 it(`get consent document of type ${index}`,43 tests.getConsentDocumentFn(index));44 it(`get consent document content of type ${index} (type id)`,45 tests.getConsentDocumentByTypeIdFn(index));46 it('login as super', shared.loginFn(config.superUser));47 it(`add translated (es) consent document ${index}`,48 tests.translateConsentDocumentFn(index, 'es'));49 it('logout as super', shared.logoutFn());50 it(`get translated (es) consent document of type ${index}`,51 tests.getTranslatedConsentDocumentFn(index, 'es'));52 });53 const listConsentDocuments = () => {54 it('list consent documents', tests.listConsentDocumentsFn());55 it('list translated (es) consent documents',56 tests.listConsentDocumentsFn({ language: 'es' }));57 it('list consent documents (with content)',58 tests.listConsentDocumentsFn({ detailed: true }));59 constNames.consentRoles.forEach((role) => {60 it(`list consent documents (for role ${role})`,61 tests.listConsentDocumentsFn({ role }));62 it(`list consent documents (for role ${role}) role only`,63 tests.listConsentDocumentsFn({ role, roleOnly: true }));64 });65 };66 listConsentDocuments();67 [0, 3, 5, 7].forEach((index) => {68 it('login as super', shared.loginFn(config.superUser));69 it(`update consent document of type ${index}`,70 tests.createConsentDocumentFn(index));71 it('logout as super', shared.logoutFn());72 it(`get consent document of type ${index}`,73 tests.getConsentDocumentFn(index));74 });75 listConsentDocuments();76 it('login as super', shared.loginFn(config.superUser));77 [1, 5].forEach((index) => {78 it(`delete consent type ${index}`, typeTests.deleteConsentTypeFn(index));79 });80 it('list consent types', typeTests.listConsentTypesFn());81 it('logout as super', shared.logoutFn());82 listConsentDocuments();83 it('login as super', shared.loginFn(config.superUser));84 _.range(documentCount, documentCount + 3).forEach((index) => {85 const options = { role: roles[index % 3] };86 it(`create consent type ${index}`,87 typeTests.createConsentTypeFn(options));88 it(`add translated (es) consent type ${index}`,89 typeTests.translateConsentTypeFn(index, 'es'));90 it(`create consent document of type ${index}`,91 tests.createConsentDocumentFn(index));92 });93 it('logout as super', shared.logoutFn());94 listConsentDocuments();95 [0, 6, 7, 8].forEach((index) => {96 it('login as super', shared.loginFn(config.superUser));97 it(`update consent document of type ${index}`,98 tests.createConsentDocumentFn(index));99 it('logout as super', shared.logoutFn());100 it(`get consent document of type ${index}`,101 tests.getConsentDocumentFn(index));102 });103 listConsentDocuments();104 it('list consent document full history', tests.listConsentDocumentsHistoryFn());105 shared.verifyUserAudit();...

Full Screen

Full Screen

consent-document.model.spec.js

Source:consent-document.model.spec.js Github

copy

Full Screen

1/* global describe,before,it */2'use strict';3process.env.NODE_ENV = 'test';4const _ = require('lodash');5const constNames = require('../models/const-names');6const SharedSpec = require('./util/shared-spec');7const Generator = require('./util/generator');8const ConsentDocumentHistory = require('./util/consent-document-history');9const consentTypeCommon = require('./util/consent-type-common');10const consentDocumentCommon = require('./util/consent-document-common');11describe('consent document unit', function consentDocumentUnit() {12 const userCount = 4;13 const documentCount = 9;14 const generator = new Generator();15 const shared = new SharedSpec(generator);16 const history = new ConsentDocumentHistory(userCount);17 const typeTests = new consentTypeCommon.SpecTests({18 generator, hxConsentType: history.hxType,19 });20 const tests = new consentDocumentCommon.SpecTests({21 generator, hxConsentDocument: history,22 });23 before(shared.setUpFn());24 const roles = [null, ...constNames.consentRoles];25 _.range(documentCount).forEach((index) => {26 const options = { role: roles[index % 3] };27 it(`create consent type ${index}`,28 typeTests.createConsentTypeFn(options));29 it(`add translated (es) consent type ${index}`,30 typeTests.translateConsentTypeFn(index, 'es'));31 });32 _.range(documentCount).forEach((index) => {33 it(`create consent document of type ${index}`,34 tests.createConsentDocumentFn(index));35 it(`get consent document of type ${index}`,36 tests.getConsentDocumentFn(index));37 it(`get consent document of type ${index} (type id)`,38 tests.getConsentDocumentByTypeIdFn(index));39 it(`add translated (es) consent document ${index}`,40 tests.translateConsentDocumentFn(index, 'es'));41 it(`get translated (es) consent document of type ${index}`,42 tests.getTranslatedConsentDocumentFn(index, 'es'));43 });44 const listConsentDocuments = () => {45 it('list consent documents', tests.listConsentDocumentsFn());46 it('list translated (es) consent documents', tests.listConsentDocumentsFn({47 language: 'es',48 }));49 it('list consent documents (with content)',50 tests.listConsentDocumentsFn({ detailed: true }));51 constNames.consentRoles.forEach((role) => {52 it(`list consent documents (for role ${role})`,53 tests.listConsentDocumentsFn({ role }));54 it(`list consent documents (for role ${role}) role only`,55 tests.listConsentDocumentsFn({ role, roleOnly: true }));56 });57 };58 listConsentDocuments();59 it('error: get consent document of invalid type id',60 tests.errorGetConsentDocumentByTypeIdFn(99999, 'consentTypeNotFound'));61 [0, 3, 5, 7].forEach((index) => {62 it(`update consent document of type ${index}`,63 tests.createConsentDocumentFn(index));64 it(`get consent document of type ${index}`,65 tests.getConsentDocumentFn(index));66 });67 listConsentDocuments();68 [1, 5].forEach((index) => {69 it(`delete consent type ${index}`, typeTests.deleteConsentTypeFn(index));70 });71 it('list consent types', typeTests.listConsentTypesFn());72 listConsentDocuments();73 _.range(documentCount, documentCount + 3).forEach((index) => {74 const options = { role: roles[index % 3] };75 it(`create consent type ${index}`,76 typeTests.createConsentTypeFn(options));77 it(`add translated (es) consent type ${index}`,78 typeTests.translateConsentTypeFn(index, 'es'));79 it(`create consent document of type ${index}`,80 tests.createConsentDocumentFn(index));81 });82 listConsentDocuments();83 [0, 6, 7, 8].forEach((index) => {84 it(`update consent document of type ${index}`,85 tests.createConsentDocumentFn(index));86 it(`get consent document of type ${index}`,87 tests.getConsentDocumentFn(index));88 });89 listConsentDocuments();90 it('list consent document full history', tests.listConsentDocumentsHistoryFn());...

Full Screen

Full Screen

typeCheck.js

Source:typeCheck.js Github

copy

Full Screen

1'use strict'2//internal constants - maybe we should export these3var TYPEOF = 'typeof';4var INSTANCEOF = 'instanceof';5// type aliases6// TODO: maybe these should be in the form of `var TYPE_BOOLEAN = typeof true`7var TYPESTRING_ANY = '*';8var TYPESTRING_FUNCTION = 'function';9var TYPESTRING_STRING = 'string'10var TYPESTRING_BOOLEAN = 'boolean'11var TYPESTRING_NUMBER = 'number'12var TYPESTRING_OBJECT = 'object'13module.exports = typeCheck;14//alias to simplify things in userland15var shorthand = {16 "any": TYPESTRING_ANY,17 "fn": TYPESTRING_FUNCTION,18 "str": TYPESTRING_STRING,19 "bool": TYPESTRING_BOOLEAN,20 "num": TYPESTRING_NUMBER,21 "obj": TYPESTRING_OBJECT22}23Object.keys(shorthand).map(function(key) {24 module.exports[key] = shorthand[key];25});26function typeCheck() {27 // taken from: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments28 // I wish I was a macro....29 var typeArgs = new Array(arguments.length);30 for (var i = 0; i < typeArgs.length; i++) {31 typeArgs[i] = arguments[i];32 }33 //typeTests is some wierd object with numeric keys34 //because apparently sparse arrays aren't a thing?35 var typeTests = typeArgs.reduce(_typeArgsReducer, {});36 var typeTestsKeys = Object.keys(typeTests)37 // length here means the last arg position of the last type checked38 // argument.39 // TODO: change this logic if we start allowing optionals of somekind40 // This is bad as we are relying on key order which is probably implentation41 // specific42 typeTests.length = parseInt(typeTestsKeys[typeTestsKeys.length-1] , 10) + 143 return function check(runtimeArgs) {44 if (runtimeArgs.length < typeTests.length) {45 throw new Error('Expected ' + typeTests.length + ' arguments but counted '+ runtimeArgs.length)46 }47 48 typeTestsKeys.forEach(function(key) {49 _otherInternalTypeCheck(typeTests[key], runtimeArgs[key], key)50 })51 };52}53function _testTypeOf(item, type, pos) {54 if (typeof item !== type) {55 throw new TypeError("Argument at position " + pos + " was of type '" + typeof item + "' but expected '" + type + "'")56 }57}58function _testInstanceOf(item, klass, pos) {59 if (item instanceof klass !== true) {60 // we assume item.constructor is not some userland made fuck-wittery61 var constructor = (item && item.constructor != undefined) ? item.constructor.name : "[no constructor]";62 throw new TypeError("Argument at position " + pos + " was instance of '" + constructor + "' but expected '" + klass.name + "'")63 }64}65// takes [testType, testData], functionArg, pos66// TODO: we're passing/leaking pos out of laziness67// TODO: why don't we just pass around refernce to the test func around?68function _otherInternalTypeCheck(testItem, arg, pos) {69 var testType = testItem[0];70 var testData = testItem[1];71 switch (testType) {72 case TYPEOF:73 _testTypeOf(arg, testData, pos)74 break;75 case INSTANCEOF:76 _testInstanceOf(arg, testData, pos)77 break;78 default:79 //don't throw here so we can be nice-ish at runtime80 // but we should never get here....81 }82}83//Designed to operate on an arguments object converted to an array84//returns an array of [typeOfCheck, SomeDataForCheck]85function _typeArgsReducer(checksToRun, typeToEnforce, position) {86 // if typeToEnforce is `undefined` or `*` we don't check it87 // if typeof typeToEnforce is "String" then thats used 88 // for a typeof test (how meta is that :-p)89 // if typeof typeToEnforce is a function then we assume it's a constructor90 // and we're doing `instanceof` checks91 if (typeToEnforce === undefined || typeToEnforce === TYPESTRING_ANY) {92 //do nothing93 } else if (typeof typeToEnforce == TYPESTRING_STRING) {94 checksToRun[position] = [TYPEOF, typeToEnforce]95 } else if (typeof typeToEnforce == TYPESTRING_FUNCTION) {96 checksToRun[position] = [INSTANCEOF, typeToEnforce]97 }98 99 return checksToRun100 ...

Full Screen

Full Screen

updaters.test.js

Source:updaters.test.js Github

copy

Full Screen

1import _updateClientMetaInfo from '../../src/client/updateClientMetaInfo'2import { defaultOptions, ssrAppId, ssrAttribute } from '../../src/shared/constants'3import metaInfoData from '../utils/meta-info-data'4import * as load from '../../src/client/load'5import { clearClientAttributeMap } from '../utils'6const updateClientMetaInfo = (type, data) => _updateClientMetaInfo(ssrAppId, defaultOptions, { [type]: data })7describe('updaters', () => {8 let html9 beforeAll(() => {10 html = document.getElementsByTagName('html')[0]11 // remove default meta charset12 Array.from(html.getElementsByTagName('meta')).forEach(el => el.parentNode.removeChild(el))13 })14 for (const type in metaInfoData) {15 const typeTests = metaInfoData[type]16 const testCases = {17 add: (tags) => {18 typeTests.add.expect.forEach((expected, index) => {19 if (!['title', 'htmlAttrs', 'headAttrs', 'bodyAttrs'].includes(type)) {20 expect(tags.tagsAdded[type][index].outerHTML).toBe(expected)21 }22 expect(html.outerHTML).toContain(expected)23 })24 },25 change: (tags) => {26 typeTests.add.expect.forEach((expected, index) => {27 if (!typeTests.change.expect.includes(expected)) {28 expect(html.outerHTML).not.toContain(expected)29 }30 })31 typeTests.change.expect.forEach((expected, index) => {32 if (!['title', 'htmlAttrs', 'headAttrs', 'bodyAttrs'].includes(type)) {33 expect(tags.tagsAdded[type][index].outerHTML).toBe(expected)34 }35 expect(html.outerHTML).toContain(expected)36 })37 },38 remove: (tags) => {39 // TODO: i'd expect tags.removedTags to be populated40 typeTests.add.expect.forEach((expected, index) => {41 expect(html.outerHTML).not.toContain(expected)42 })43 typeTests.change.expect.forEach((expected, index) => {44 expect(html.outerHTML).not.toContain(expected)45 })46 expect(html.outerHTML).not.toContain(`<${type}`)47 }48 }49 describe(`${type} type tests`, () => {50 beforeAll(() => clearClientAttributeMap())51 Object.keys(typeTests).forEach((action) => {52 const testInfo = typeTests[action]53 // return when no test case available54 if (!testCases[action] && !testInfo.test) {55 return56 }57 const defaultTestFn = () => {58 const tags = updateClientMetaInfo(type, testInfo.data)59 if (testCases[action]) {60 testCases[action](tags)61 }62 return tags63 }64 let testFn65 if (testInfo.test) {66 testFn = testInfo.test('client', defaultTestFn)67 if (testFn === true) {68 testFn = defaultTestFn69 }70 } else {71 testFn = defaultTestFn72 }73 if (testFn && typeof testFn === 'function') {74 test(`${action} a tag`, () => {75 expect.hasAssertions()76 testFn()77 })78 }79 })80 })81 }82})83describe('extra tests', () => {84 test('adds callback listener on hydration', () => {85 const addListeners = load.addListeners86 const addListenersSpy = jest.spyOn(load, 'addListeners').mockImplementation(addListeners)87 const html = document.getElementsByTagName('html')[0]88 html.setAttribute(ssrAttribute, 'true')89 const data = [{ src: 'src1', [defaultOptions.tagIDKeyName]: 'content', callback: () => {} }]90 const tags = updateClientMetaInfo('script', data)91 expect(tags).toBe(false)92 expect(html.hasAttribute(ssrAttribute)).toBe(false)93 expect(addListenersSpy).toHaveBeenCalledTimes(1)94 })...

Full Screen

Full Screen

type.js

Source:type.js Github

copy

Full Screen

1import {identity, toBoolean, toDate, toNumber, toString} from 'vega-util';2export var typeParsers = {3 boolean: toBoolean,4 integer: toNumber,5 number: toNumber,6 date: toDate,7 string: toString,8 unknown: identity9};10var typeTests = [11 isBoolean,12 isInteger,13 isNumber,14 isDate15];16var typeList = [17 'boolean',18 'integer',19 'number',20 'date'21];22export function inferType(values, field) {23 if (!values || !values.length) return 'unknown';24 var value, i, j, t = 0,25 n = values.length,26 m = typeTests.length,27 a = typeTests.map(function(_, i) { return i + 1; });28 for (i=0, n=values.length; i<n; ++i) {29 value = field ? values[i][field] : values[i];30 for (j=0; j<m; ++j) {31 if (a[j] && isValid(value) && !typeTests[j](value)) {32 a[j] = 0;33 ++t;34 if (t === typeTests.length) return 'string';35 }36 }37 }38 t = a.reduce(function(u, v) { return u === 0 ? v : u; }, 0) - 1;39 return typeList[t];40}41export function inferTypes(data, fields) {42 return fields.reduce(function(types, field) {43 types[field] = inferType(data, field);44 return types;45 }, {});46}47// -- Type Checks ----48function isValid(_) {49 return _ != null && _ === _;50}51function isBoolean(_) {52 return _ === 'true' || _ === 'false' || _ === true || _ === false;53}54function isDate(_) {55 return !isNaN(Date.parse(_));56}57function isNumber(_) {58 return !isNaN(+_) && !(_ instanceof Date);59}60function isInteger(_) {61 return isNumber(_) && (_=+_) === ~~_;...

Full Screen

Full Screen

alltests.js

Source:alltests.js Github

copy

Full Screen

1/*[[[cog2import cog, pathlib3ext=pathlib.Path(cog.inFile).suffix4cog.outl("""5import {{ typeTests, seqEqTests, timesTests, exceptionTests, queueTests, treeTests }} from './codetests{ext}'6// import {{ tokenTests }} from './tokentests{ext}'7""".format(ext=ext))8]]]*/9import { typeTests, seqEqTests, timesTests, exceptionTests, queueTests, treeTests } from './codetests.js'10// import { tokenTests } from './tokentests.js'11//[[[end]]]12const allTests = () => [13 typeTests,14 seqEqTests,15 timesTests,16 exceptionTests,17 queueTests,18 treeTests19 // evaluateTests(0)20]21console.log(allTests().map(t => t().join('\n')).join('\n'))...

Full Screen

Full Screen

alltests.mjs

Source:alltests.mjs Github

copy

Full Screen

1/*[[[cog2import cog, pathlib3ext=pathlib.Path(cog.inFile).suffix4cog.outl("""5import {{ typeTests, seqEqTests, timesTests, exceptionTests, queueTests, treeTests }} from './codetests{ext}'6// import {{ tokenTests }} from './tokentests{ext}'7""".format(ext=ext))8]]]*/9import { typeTests, seqEqTests, timesTests, exceptionTests, queueTests, treeTests } from './codetests.mjs'10// import { tokenTests } from './tokentests.mjs'11//[[[end]]]12const allTests = () => [13typeTests,14seqEqTests,15timesTests,16exceptionTests,17queueTests,18treeTests19// evaluateTests(0)20];21console.log(allTests().map(t => t().join('\n')).join('\n'));...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful