Best JavaScript code snippet using jest
initBackendnCommit.js
Source:initBackendnCommit.js
1const execa = require('execa');2const path = require('path');3module.exports = async (backPath) => {4 try {5 let cwdPath = path.normalize(path.resolve(backPath));6 const gitInit = await execa('git', ['init'], {cwd: cwdPath});7 if(!gitInit.failed && !gitInit.killed && !gitInit.timedOut && !gitInit.isCancelled){8 const gitAdd = await execa('git', ['add', '.'], {cwd: cwdPath});9 if(!gitAdd.failed && !gitAdd.killed && !gitAdd.timedOut && !gitAdd.isCancelled){10 const gitCommit = await execa('git', ['commit', '-m', '%Automated Bot Commit%'],{cwd: cwdPath});11 if(!gitCommit.failed && !gitCommit.killed && !gitCommit.timedOut && !gitCommit.isCancelled){12 return {13 res: true,14 initOut: gitInit.stdout,15 addOut: gitAdd.stdout,16 commitOut: gitCommit.stdout,17 commands: {18 init: gitInit.command,19 add: gitAdd.command,20 commit: gitCommit.command21 },22 exitCodes: {23 init: gitInit.exitCode,24 add: gitAdd.exitCode,25 commit: gitCommit.exitCode26 }27 }28 } else {29 return {30 res: false,31 initOut: gitInit.stdout,32 addOut: gitAdd.stdout,33 commitOut: gitCommit.stderr,34 commands: {35 init: gitInit.command,36 add: gitAdd.command,37 commit: gitCommit.command38 },39 exitCodes: {40 init: gitInit.exitCode,41 add: gitAdd.exitCode,42 commit: gitCommit.exitCode43 }44 }45 }46 } else {47 return {48 res: false,49 initOut: gitInit.stdout,50 addOut: gitAdd.stderr,51 commitOut: 'Not Executed',52 commands: {53 init: gitInit.command,54 add: gitAdd.command,55 commit: "Not Executed"56 },57 exitCodes: {58 init: gitInit.exitCode,59 add: gitAdd.exitCode,60 commit: "Not Executed"61 }62 }63 }64 } else {65 return {66 res: false,67 initOut: gitInit.stderr,68 addOut: "Not Executed",69 commitOut: "Not Executed",70 commands: {71 init: gitInit.command,72 add: "Not Executed",73 commit: "Not Executed"74 },75 exitCodes: {76 init: gitInit.exitCode,77 add: "Not Executed",78 commit: "Not Executed"79 }80 }81 }82 } catch(e) {83 console.log(e);84 return {85 res: false,86 initOut: e.stderr,87 addOut: e.stderr,88 commitOut: e.stderr,89 commands: {90 init: e.command,91 add: e.command,92 commit: e.command93 },94 exitCodes: {95 init: e.exitCode,96 add: e.exitCode,97 commit: e.exitCode98 }99 }100 }...
prompt.test.js
Source:prompt.test.js
1const { describe, it } = require('mocha');2const sinon = require('sinon');3const assume = require('assume');4const prompt = require('../lib/prompt');5describe('prompt', function () {6 let mockContext, mockUtils, promptStub;7 beforeEach(() => {8 promptStub = sinon.stub();9 mockContext = {10 appName: 'bogus-app'11 };12 mockUtils = {13 prompt: promptStub14 };15 });16 it('is async function', function () {17 assume(prompt).to.be.an('asyncfunction');18 });19 it('does not prompt if gitInit set in context', async () => {20 mockContext.gitInit = false;21 await prompt({}, mockContext, mockUtils);22 // eslint-disable-next-line require-atomic-updates23 mockContext.gitInit = true;24 await prompt({}, mockContext, mockUtils);25 assume(promptStub).not.called();26 });27 it('prompts if gitInit not set in context', async () => {28 promptStub.returns({ gitInit: true });29 await prompt({}, mockContext, mockUtils);30 assume(promptStub).is.called();31 assume(promptStub.args[0][0][0]).property('name', 'gitInit');32 });33 it('sets gitInit in updated context', async () => {34 promptStub.returns({ gitInit: true });35 const result = await prompt({}, mockContext, mockUtils);36 assume(result).not.equals(mockContext);37 assume(result).property('gitInit', true);38 });39 it('returns original context if no prompt', async () => {40 mockContext.gitInit = true;41 const result = await prompt({}, mockContext, mockUtils);42 assume(result).equals(mockContext);43 });...
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.
|<p>it('check_object_of_Car', () => {</p><p>
expect(newCar()).toBeInstanceOf(Car);</p><p>
});</p>|
| :- |
Get 100 minutes of automation test minutes FREE!!