How to use getMarkdown method in Jest

Best JavaScript code snippet using jest

buildMarkdown.spec.js

Source:buildMarkdown.spec.js Github

copy

Full Screen

1import documentation from 'documentation';2import buildMarkdown from './';3function getMarkdown(documentationSource, args) {4 return documentation5 .build([{ source: documentationSource }], { shallow: true })6 .then(comments => buildMarkdown(comments, args));7}8describe('buildMarkdown', () => {9 describe('for class', () => {10 it('should render markdown for class with constructor', async () => {11 const documentationSource = `12 /**13 * Component description14 * 15 * @example16 * new Component({visible: true})17 */18 class Component {19 /**20 * creates new Component21 */ 22 constructor(config: any) {}23 24 /**25 * show26 */27 show() {}28 }29 `;30 const markdown = await getMarkdown(documentationSource);31 expect(markdown).toMatchSnapshot();32 });33 });34 describe('for API class', () => {35 const title = 'API Methods';36 it('should render markdown for getters/setters', async () => {37 const documentationSource = `38 /** Example class jsdoc */39 class API {40 /**41 * \`isVisible\` getter comment42 */43 get isVisible(): boolean {44 return true;45 }46 47 /**48 * \`width\` setter comment49 */50 set width(value: number) {51 console.log(value)52 }53 }54 `;55 const markdown = await getMarkdown(documentationSource, { title });56 expect(markdown).toMatchSnapshot();57 });58 it('should render markdown for methods default value', async () => {59 const documentationSource = `60 /** Example class jsdoc */61 class API {62 /**63 * myMethod comment64 * @param [x=''] - \`x\` description 65 * 66 */67 myMethod(x: string) {}68 }69 `;70 const markdown = await getMarkdown(documentationSource, { title });71 expect(markdown).toMatchSnapshot();72 });73 it('should render markdown for methods with @returns comment', async () => {74 const documentationSource = `75 /** Example class jsdoc */76 class API {77 /**78 * myMethod comment79 * @param x - \`x\` description 80 * 81 * @returns returns comment82 */83 myMethod(x: string): string {84 return x;85 }86 }87 `;88 const markdown = await getMarkdown(documentationSource, { title });89 expect(markdown).toMatchSnapshot();90 });91 it('should render markdown for methods with UnionType with literals as @param type', async () => {92 const documentationSource = `93 /** Example class jsdoc */94 class API {95 /**96 * myMethod comment97 * @param y - \`y\` comment98 */99 myMethod(y: 'bla' | 'not bla' | 7 | null) {100 return y;101 }102 }103 `;104 const markdown = await getMarkdown(documentationSource, { title });105 expect(markdown).toMatchSnapshot();106 });107 it('should render markdown for methods with UnionType with NOT literal as @param type', async () => {108 const documentationSource = `109 /** Example class jsdoc */110 class API {111 /**112 * myMethod comment113 * @param y - \`y\` comment114 */115 myMethod(y: number | null) {116 return y;117 }118 }119 `;120 const markdown = await getMarkdown(documentationSource, { title });121 expect(markdown).toMatchSnapshot();122 });123 it('should render markdown for methods with @example end @note', async () => {124 const documentationSource = `125 /** Example class jsdoc */126 class API {127 /**128 * myMethod comment129 * @param x - \`x\` description. see http://example.com130 * 131 * @note132 * \`myMethod\` note 1133 *134 * @example <caption>test example caption</caption>135 * console.log('example')136 *137 * @example138 * console.log('example')139 *140 * @note141 * \`myMethod\` note 2142 * Read more about [myMethod](/my-method)143 *144 */145 myMethod(x: string): string {146 return x;147 }148 }149 `;150 const markdown = await getMarkdown(documentationSource, { title });151 expect(markdown).toMatchSnapshot();152 });153 it('should render markdown for methods with @deprecated', async () => {154 const documentationSource = `155 /** Example class jsdoc */156 class API {157 /**158 * show component 159 * @deprecated use method \`show()\`160 */161 doShow() {}162 163 /**164 * show component165 */166 show() {}167 }168 `;169 const markdown = await getMarkdown(documentationSource, { title });170 expect(markdown).toMatchSnapshot();171 });172 it('should render markdown for methods with `...rest` as param', async () => {173 const documentationSource = `174 /** Example class jsdoc */175 class API {176 /**177 * myMethod comment178 */179 myMethod(...arr: string[]): string[] {180 return arr;181 }182 }183 `;184 const markdown = await getMarkdown(documentationSource, { title });185 expect(markdown).toMatchSnapshot();186 });187 it('should render markdown for methods with `optional` as param', async () => {188 const documentationSource = `189 /** Example class jsdoc */190 class API {191 /**192 * myMethod comment193 */194 myMethod(x: ?number): number {195 return number;196 }197 }198 `;199 const markdown = await getMarkdown(documentationSource, { title });200 expect(markdown).toMatchSnapshot();201 });202 it('should render markdown for methods interface as return type', async () => {203 const documentationSource = `204 /**205 * MyResult interface206 * @property a - \`a\` description207 * @property b - \`b\` description208 */209 interface MyResult {210 a: string;211 b?: number;212 }213 /** Example class jsdoc */214 class API {215 /**216 * myMethod comment217 * @param y - \`y\` comment218 */219 myMethod(y: 'bla' | 'not bla'): MyResult {220 return y;221 }222 }223 `;224 const markdown = await getMarkdown(documentationSource, { title });225 expect(markdown).toMatchSnapshot();226 });227 it('should render markdown sections in valid order', async () => {228 const documentationSource = `229 /** Example class jsdoc */230 class API {231 /**232 * myMethod1 comment233 * @param x - \`x\` description234 * 235 * @example <caption>test example caption</caption>236 * console.log('example')237 * @note238 * \`myMethod1\` note 239 * Read more about [myMethod](/my-method)240 *241 * @returns returns comment242 */243 myMethod1(x: string): string {244 return x;245 }246 247 /**248 * myMethod2 comment249 * @param y - y comment250 * 251 * @example252 * console.log('example')253 */254 myMethod2(y: 'bla' | 'not bla'): string {255 return y;256 }257 }258 `;259 const markdown = await getMarkdown(documentationSource, { title });260 expect(markdown).toMatchSnapshot();261 });262 });263 describe('for functions', async () => {264 const title = 'Functions';265 it('should render valid markdown', async () => {266 const documentationSource = `267 /**268 * MyFuncResult interface269 * @property a - \`a\` description270 * @property b - \`b\` description271 */272 interface MyFuncResult {273 a: string;274 b: number;275 }276 /**277 * myFunc1 description278 * @param x - \`x\` description 279 */280 function myFunc1(x: number): number {}281 /**282 * myFunc2 description283 * @param x - \`x\` description 284 * @param y - \`y\` description285 *286 * @example <caption>MyFunc example</caption>287 * 288 * console.log(myFunc(3, 2))289 * // {a: '3', b: 2}290 */291 function myFunc2(x: number, y:number): MyFuncResult {}292 `;293 const markdown = await getMarkdown(documentationSource, { title });294 expect(markdown).toMatchSnapshot();295 });296 it('should render valid markdown with function as argument', async () => {297 const documentationSource = `298 /**299 * @param name - event name 300 * @param fn - event handler 301 */302 function myFunc(name: string, fn: (name: string, data: Object) => any) {}303 `;304 const markdown = await getMarkdown(documentationSource, { title });305 expect(markdown).toMatchSnapshot();306 });307 it('should render valid markdown with UnionType in TypeApplication as argument', async () => {308 const documentationSource = `309 /**310 * @param fn - event handler 311 */312 function myFunc(fn: (value: string | null) => void) {}313 `;314 const markdown = await getMarkdown(documentationSource, { title });315 expect(markdown).toMatchSnapshot();316 });317 it('should render valid markdown with function as return type', async () => {318 const documentationSource = `319 /**320 * @returns myFunc result function321 */322 function myFunc(): (flag: boolean) => void {}323 `;324 const markdown = await getMarkdown(documentationSource, { title });325 expect(markdown).toMatchSnapshot();326 });327 it('should render valid markdown with function in return type interface', async () => {328 const documentationSource = `329 /**330 * @property update - update entity331 * @property destroy - destroy entity332 */333 interface MyEntity {334 id: string;335 title: string;336 updateTitle(id: string, title: string): Promise<any>;337 destroy(): void;338 }339 340 /**341 * create new entity342 * @param title - entity title343 * @returns new entity344 */345 function create(title: string): MyEntity {}346 `;347 const markdown = await getMarkdown(documentationSource, { title });348 expect(markdown).toMatchSnapshot();349 });350 });351 describe('with ApplicationType as return type', () => {352 const title = 'API Methods';353 it('should render markdown for methods with Promise as @returns type', async () => {354 const documentationSource = `355 /**356 * @returns returns comment357 */358 function myFn(): Promise<string> {359 return x;360 }361 `;362 const markdown = await getMarkdown(documentationSource, { title });363 expect(markdown).toMatchSnapshot();364 });365 it('should render markdown for methods with Promise & interface as @returns type', async () => {366 const documentationSource = `367 /** */368 interface IResult {369 x: number;370 y: number;371 }372 /**373 * @returns returns comment374 */375 function myFn(): Promise<IResult> {376 return {x: 1, y: 1};377 }378 `;379 const markdown = await getMarkdown(documentationSource, { title });380 expect(markdown).toMatchSnapshot();381 });382 it('should render markdown for methods with Array as @returns type', async () => {383 const documentationSource = `384 /**385 * @returns returns comment386 */387 function myFn(): string[] {388 return [''];389 }390 `;391 const markdown = await getMarkdown(documentationSource, { title });392 expect(markdown).toMatchSnapshot();393 });394 it('should render markdown for methods with Array & interface as @returns type', async () => {395 const documentationSource = `396 /** */397 interface IResult {398 x: number;399 y: number;400 }401 /**402 * @returns returns comment403 */404 function myFn(): IResult[] {405 return [{x: 1, y: 1}];406 }407 `;408 const markdown = await getMarkdown(documentationSource, { title });409 expect(markdown).toMatchSnapshot();410 });411 });...

Full Screen

Full Screen

htmlToMd.js

Source:htmlToMd.js Github

copy

Full Screen

...9 }10 getChilden(el) {11 return el.children();12 }13 getMarkdown(el) {14 let that = this;15 let mainEl = el ? this.$(el) : this.mainEl;16 let cd = mainEl.children();17 let content = '';18 cd.each(function (index, el) {19 content += that.parse(el);20 });21 return content;22 }23 parse(el) {24 let nodeName = el.nodeName;25 let content = '';26 switch (nodeName) {27 case 'SPAN':28 content = '';29 break;30 case 'H1':31 content = `# ${this.getHtext(el)}\n`;32 break;33 case 'H2':34 content = `\n## ${this.getHtext(el)}\n`;35 break;36 case 'H3':37 content = `\n### ${this.getHtext(el)}\n`;38 break;39 case 'H4':40 content = `\n#### ${this.getHtext(el)}\n`;41 break;42 case 'H5':43 content = `\n##### ${this.getHtext(el)}\n`;44 break;45 case 'TABLE': {46 let tempContent = this.$(el).prop("innerText");47 tempContent = tempContent.replace(new RegExp(/( )/g), ' | ');48 let tempArr = tempContent.split('\n');49 let tempArr2 = tempArr[0].split('|');50 let tempArr3 = [];51 Array.from({52 length: tempArr2.length53 }).forEach(() => tempArr3.push('---'));54 tempArr.splice(1, 0, tempArr3.join('|'));55 tempContent = `\n${tempArr.join('\n')}\n`;56 content = this.replaceAForTable(tempContent, this.$(el));57 }58 break;59 case 'P': {60 let className = this.$(el).attr('class');61 if (className !== 'first admonition-title') {62 content = this.getPcontent(this.$(el));63 }64 }65 break;66 case 'IMG': {67 let imgSrc = this.$(el).attr('src');68 let imgNameArr = imgSrc.split('/');69 let imgName = imgNameArr[imgNameArr.length - 1];70 let fileName = imgName.split('.')[0];71 content = `\n![${fileName}](${this.baseImgDir}${imgName})\n`;72 }73 break;74 case 'DIV': {75 let className = this.$(el).attr('class');76 if (!className) {77 content = this.getMarkdown(el);78 } else if (className === 'math notranslate nohighlight') {79 content = `\n<div class="math notranslate nohighlight">\nIt's a mathematical formula.\n</div>\n`;80 } else if (className === 'admonition note') {81 let pEl = this.$(el).find('.first.admonition-title');82 let title = pEl.text();83 let tempContent = this.getMarkdown(el);84 content = `\n::: tip ${title}\n${tempContent}\n:::\n`;85 } else if (className === 'admonition warning') {86 let pEl = this.$(el).find('.first.admonition-title');87 let title = pEl.text();88 let tempContent = this.getMarkdown(el);89 content = `\n::: danger ${title}\n${tempContent}\n:::\n`;90 } else if (className === 'section' || className === 'toctree-wrapper compound') {91 content = this.getMarkdown(el);92 } else if (className.indexOf('highlight-') !== -1) {93 let langName = className.split('highlight-')[1].split(' ')[0];94 if (langName === 'ipython' || langName === 'default' || langName === 'ipython3') langName = 'python';95 if (langName === 'console' || langName === 'text' || langName === 'none') {96 langName = '';97 }98 let tempContent = this.uReplaceStr(this.$(el).text());99 if (tempContent) {100 content = `\n\`\`\` ${langName}\n${tempContent}\n\`\`\`\n`;101 }102 } else {103 content = this.getMarkdown(el);104 }105 }106 break;107 case 'OL': {108 let className = this.$(el).attr('class');109 let that = this;110 let templateContent = '';111 if (className === 'arabic simple') {112 let lis = this.$(el).find('li');113 lis.each(function (index, el) {114 templateContent = templateContent + `\n1. ${that.uReplaceStr(that.getPcontent(that.$(el)))}`;115 });116 content = templateContent + '\n';117 }118 }119 break;120 case 'UL': {121 let className = this.$(el).attr('class');122 let that = this;123 let templateContent = '';124 if (!className) {125 let lis = this.$(el).find('li');126 lis.each(function (index, el) {127 templateContent = templateContent + `\n- ${that.uReplaceStr(that.getMarkdown(el))}`;128 });129 content = templateContent + '\n';130 } else if (className.indexOf('simple') !== -1) {131 let lis = this.$(el).find('li');132 lis.each(function (index, el) {133 templateContent = templateContent + `\n- ${that.uReplaceStr(that.getPcontent(that.$(el)))}`;134 });135 content = templateContent + '\n';136 } else {137 let lis = this.$(el).find('li');138 lis.each(function (index, el) {139 templateContent = templateContent + `\n- ${that.uReplaceStr(that.getMarkdown(el))}`;140 });141 content = templateContent + '\n';142 }143 }144 break;145 case 'BLOCKQUOTE': {146 content = this.getMarkdown(el);147 }148 break;149 case 'DL': {150 content = this.getMarkdown(el);151 }152 break;153 case 'DT': {154 content = this.getPcontent(el);155 }156 break;157 case 'DD': {158 content = this.getMarkdown(el);159 }160 break;161 default:162 content = '';163 break;164 }165 return content;166 }167 getHtext(el) {168 let tempContent = this.replaceCode(this.$(el));169 let text = this.$(this.$(tempContent)).text();170 return text.replace('¶', '');171 }172 getPcontent(el) {173 let tempContent = this.replaceCode(this.$(el));174 tempContent = this.replaceA(this.$(tempContent));175 tempContent = this.replaceCite(this.$(tempContent));176 tempContent = this.replaceStrong(this.$(tempContent));177 tempContent = this.replaceSpan(this.$(tempContent));178 tempContent = this.replaceEm(this.$(tempContent));179 tempContent = this.$(tempContent).text();180 let content = `\n${tempContent}\n`;181 return content;182 }183 replaceCode($el) {184 let that = this;185 let hContent = $el.prop("outerHTML");186 let codes = $el.find('code');187 if (codes.length) {188 codes.each(function (index, el) {189 let outHtml = that.$(el).prop("outerHTML");190 let text = that.$(el).text();191 hContent = hContent.replace(outHtml, `\`\`${text}\`\``);192 });193 }194 return hContent;195 }196 replaceA($el) {197 let that = this;198 let hContent = $el.prop("outerHTML");199 let as = $el.find('a');200 if (as.length) {201 as.each(function (index, el) {202 let outHtml = that.$(el).prop("outerHTML");203 let href = that.$(el).attr('href');204 if (href.substring(0, 2) === '..') {205 href = that.baseUrl + href.substring(2, href.length);206 }207 let text = that.$(el).text();208 hContent = hContent.replace(outHtml, `[${text}](${href})`);209 });210 }211 return hContent;212 }213 replaceAForTable(content, $el) {214 let that = this;215 let as = $el.find('a');216 if (as.length) {217 as.each(function (index, el) {218 let href = that.$(el).attr('href');219 let text = that.$(el).text();220 if (href.substring(0, 2) === '..') {221 href = that.baseUrl + href.substring(2, href.length);222 }223 content = content.replace(text, `[${text}](${href})`);224 });225 }226 return content;227 }228 replaceSpan($el) {229 let that = this;230 let hContent = $el.prop("outerHTML");231 let spans = $el.find('span');232 if (spans.length) {233 spans.each(function (index, el) {234 let outHtml = that.$(el).prop("outerHTML");235 let text = that.$(el).text();236 let className = that.$(el).attr('class');237 if (className === 'classifier' || className === 'versionmodified') {238 hContent = hContent.replace(outHtml, `*${that.uReplaceStr(text)}* `);239 } else {240 hContent = hContent.replace(outHtml, `${text}`);241 }242 });243 }244 return hContent;245 }246 replaceStrong($el) {247 let that = this;248 let hContent = $el.prop("outerHTML");249 let strongs = $el.find('strong');250 if (strongs.length) {251 strongs.each(function (index, el) {252 let outHtml = that.$(el).prop("outerHTML");253 let text = that.$(el).text();254 hContent = hContent.replace(outHtml, `**${text}**`);255 });256 }257 return hContent;258 }259 replaceCite($el) {260 let that = this;261 let hContent = $el.prop("outerHTML");262 let cites = $el.find('cite');263 if (cites.length) {264 cites.each(function (index, el) {265 let outHtml = that.$(el).prop("outerHTML");266 let text = that.$(el).text();267 hContent = hContent.replace(outHtml, `*${text}*`);268 });269 }270 return hContent;271 }272 replaceEm($el) {273 let that = this;274 let hContent = $el.prop("outerHTML");275 let ems = $el.find('em');276 if (ems.length) {277 ems.each(function (index, el) {278 let outHtml = that.$(el).prop("outerHTML");279 let text = that.$(el).text();280 hContent = hContent.replace(outHtml, `*${text}*`);281 });282 }283 return hContent;284 }285 uReplaceStr(str) {286 return str.replace(/(^\n*)|(\n*$)/g, "").replace(/(^\s*)|(\s*$)/g, "");287 }288 }289 window.c = new Convert({290 baseUrl: 'https://pandas.pydata.org/pandas-docs/stable',291 baseImgDir: '/static/images/',292 el: `#comparison-with-stata`,293 $: window.$294 });295 // c.getMarkdown();296 console.log(window.c.getMarkdown());...

Full Screen

Full Screen

Page.spec.js

Source:Page.spec.js Github

copy

Full Screen

...67 })68 test('should be able to set permalink from global pattern', async () => {69 const permalinkPattern = '/:year/:month/:day/:slug'70 const { relative, filePath } = getDocument('2020-01-01-date.md')71 const markdown = getMarkdown()72 const page = await setupPage({ filePath, relative, permalinkPattern }, { markdown })73 expect(page.path).toBe('/2020/01/01/date/')74 expect(page.regularPath).toBe('/2020-01-01-date.html')75 const pageWithLocalePath = await setupPage(76 { filePath, relative, permalinkPattern },77 { computed: { setPage () {}, $localePath: '/zh/' }, markdown }78 )79 expect(pageWithLocalePath.path).toBe('/zh/2020/01/01/date/')80 })81})82describe('markdown page', () => {83 test('should be able to pointing to a markdown file', async () => {84 const { relative, filePath } = getDocument('README.md')85 const markdown = getMarkdown()86 const page = await setupPage({ filePath, relative }, { markdown })87 expect(page._filePath).toBe(filePath)88 expect(page.regularPath).toBe('/')89 expect(page.path).toBe('/')90 expect(page.frontmatter).toEqual({})91 const content = await readFile(filePath)92 expect(page._content).toBe(content)93 expect(page._strippedContent).toBe(content)94 })95 test('should be able add a page with explicit content', async () => {96 const { filePath } = getDocument('README.md')97 const content = await readFile(filePath)98 const markdown = getMarkdown()99 const page = await setupPage({ content }, { markdown })100 expect(page._content).toBe(content)101 expect(page._strippedContent).toBe(content)102 })103 test('should work with frontmatter when pointing to a markdown file', async () => {104 const { relative, filePath } = getDocument('alpha.md')105 const title = 'VuePress Alpha' // from fixture106 const markdown = getMarkdown()107 const page = await setupPage({ filePath, relative }, { markdown })108 expect(page._filePath).toBe(filePath)109 expect(page.regularPath).toBe('/alpha.html')110 expect(page.path).toBe('/alpha.html')111 expect(page.frontmatter.title).toBe(title)112 expect(page._content.startsWith('---')).toBe(true)113 expect(page._strippedContent.startsWith('---')).toBe(false)114 })115 test('should extract any content above <!-- more --> as excerpt', async () => {116 const { relative, filePath } = getDocument('excerpt.md')117 const markdown = getMarkdown()118 const page = await setupPage({ filePath, relative }, { markdown })119 expect(page.excerpt).toMatchSnapshot()120 })121 test('should extract level 2 and 3 headers by default', async () => {122 const { relative, filePath } = getDocument('alpha.md')123 const markdown = getMarkdown()124 const page = await setupPage({ filePath, relative }, { markdown })125 expect(page.headers).toMatchSnapshot()126 })127 test('should extract headers by config', async () => {128 const { relative, filePath } = getDocument('alpha.md')129 const markdown = getMarkdown()130 const extractHeaders = ['h1', 'h2']131 const page = await setupPage({ filePath, relative, extractHeaders }, { markdown })132 expect(page.headers).toMatchSnapshot()133 })134})135describe('title', () => {136 test('should be able to set title', async () => {137 const title = 'VuePress'138 const page = await setupPage({ path: '/', title })139 expect(page.title).toBe(title)140 })141 test('should set title from frontmatter', async () => {142 const title = 'VuePress Alpha' // from fixture143 const { relative, filePath } = getDocument('alpha.md')144 const markdown = getMarkdown()145 const page = await setupPage({ filePath, relative }, { markdown })146 expect(page.title).toBe(title)147 })148 test('should use first header in markdown to set title ', async () => {149 const title = 'Home' // from fixture150 const { relative, filePath } = getDocument('README.md')151 const markdown = getMarkdown()152 const page = await setupPage({ filePath, relative }, { markdown })153 expect(page.title).toBe(title)154 })155})156describe('enhancer', () => {157 test('should loop over sync enhancers', async () => {158 const page = await setupPage({ path: '/' })159 const enhancers = [160 {161 name: 'foo',162 value: jest.fn()163 },164 {165 name: 'foo',166 value: jest.fn()167 }168 ]169 await page.enhance(enhancers)170 return enhancers.map(enhancer => expect(enhancer.value).toHaveBeenCalled())171 })172 test('should loop over sync and async enhancers', async () => {173 const page = await setupPage({ path: '/' })174 const enhancers = [175 {176 name: 'foo',177 value: jest.fn()178 },179 {180 name: 'foo',181 value: jest.fn()182 }183 ]184 const mixedEnhancers = [...enhancers, {185 name: 'blog',186 value: jest.fn().mockResolvedValue({})187 }]188 await page.enhance(mixedEnhancers)189 return mixedEnhancers.map(enhancer => expect(enhancer.value).toHaveBeenCalled())190 })191 test('should log and throw an error when enhancing fails', async () => {192 global.console.log = jest.fn()193 const pluginName = 'error-plugin'194 const page = await setupPage({ path: '/' })195 const error = { errorMessage: 'this is an error message' }196 await expect(page.enhance([{197 name: pluginName,198 value: jest.fn().mockRejectedValue(error)199 }])).rejects.toThrowError(`[${pluginName}] execute extendPageData failed.`)200 expect(console.log).toHaveBeenCalledWith(error)201 })202})203describe('public api', () => {204 test('dirname', async () => {205 const dirname = 'docs'206 const { relative, filePath } = getDocument('README.md')207 const markdown = getMarkdown()208 const page = await setupPage({ filePath, relative }, { markdown })209 expect(page.dirname).toBe(dirname)210 })211 test('filename', async () => {212 const filename = 'README'213 const { relative, filePath } = getDocument(`${filename}.md`)214 const markdown = getMarkdown()215 const page = await setupPage({ filePath, relative }, { markdown })216 expect(page.filename).toBe(filename)217 })218 test('slug', async () => {219 const markdown = getMarkdown()220 const dirname = 'docs'221 const indexPageFixture = getDocument('README.md')222 const indexPage = await setupPage(223 { filePath: indexPageFixture.filePath, relative: indexPageFixture.relative }, { markdown }224 )225 expect(indexPage.slug).toBe(dirname)226 const filename = 'alpha'227 const pageFixture = getDocument(`${filename}.md`)228 const page = await setupPage(229 { filePath: pageFixture.filePath, relative: pageFixture.relative }, { markdown }230 )231 expect(page.slug).toBe(filename)232 })233 test('strippedFilename', async () => {234 const { relative, filePath } = getDocument('2020-01-01-date.md')235 const markdown = getMarkdown()236 const page = await setupPage({ filePath, relative }, { markdown })237 expect(page.strippedFilename).toBe('date')238 })239 test('date', async () => {240 const frontmatter = { date: '2020-01-01' }241 const dateInFrontmatterPage = await setupPage({ path: '/', frontmatter })242 expect(dateInFrontmatterPage.date).toBe('2020-01-01')243 const { relative, filePath } = getDocument('2020-01-01-date.md')244 const markdown = getMarkdown()245 const dateInPathPage = await setupPage({ filePath, relative }, { markdown })246 expect(dateInPathPage.date).toBe('2020-01-01')247 })...

Full Screen

Full Screen

MarkDownEditor.js

Source:MarkDownEditor.js Github

copy

Full Screen

...28}) => {29 const dispatch = useDispatch();30 const toastRef = React.useRef(null);31 const getContent = async () => {32 const getMarkDown = toastRef.current.getInstance().getMarkdown();33 if (!validatePost(title, getMarkDown)) {34 return;35 }36 await dispatch(37 createPostToAxios({ category, title, contents: getMarkDown }),38 );39 history.replace('/');40 };41 const updatePost = async () => {42 const getMarkDown = toastRef.current.getInstance().getMarkdown();43 if (!validatePost(title, getMarkDown)) {44 return;45 }46 await dispatch(47 updatePostToAxios(currentPost.id, {48 id: currentPost.id,49 category,50 title: updateTitle,51 contents: getMarkDown,52 }),53 );54 history.replace(`/post/${currentPost.id}`);55 };56 const isBelowTablet = window.matchMedia('(max-width: 768px)').matches;...

Full Screen

Full Screen

routes.js

Source:routes.js Github

copy

Full Screen

...5 '/': (params) => [6 'start',7 () => new Promise((resolve, reject) => {8 parallelPromise([9 getMarkdown('start'),10 getMarkdown('skills'),11 getMarkdown('references')12 ])13 .then((mdArr) => {14 resolve({ sections: mdArr.map((md) => md[0].html) })15 })16 .catch(reject)17 })18 ],19 '/projects': (params) => [20 'projects',21 () => new Promise((resolve, reject) => {22 getMarkdown('projects/*')23 .then((mdArr) => resolve({ projects: mdArr.map((md) => md.html) }))24 .catch(reject)25 })26 ],27 '/anotherblog': (params) => [28 'blog',29 () => new Promise((resolve, reject) => {30 getArticles('blog')31 .then((articles) => resolve({ articles }))32 .catch(reject)33 })34 ],35 '/anotherblog/:article': (params) => [36 'blogArticle',37 () => new Promise((resolve, reject) => {38 getArticles('blog')39 .then((articles) =>40 resolve(articles.filter((el) => el.name === params.article)[0])41 )42 .catch(reject)43 }),44 `blogArticle/${params.article}`45 ],46 '/ipa': (params) => [47 'generic',48 () => new Promise((resolve, reject) => {49 getMarkdown('dispo_interaktiver_news_artikel')50 .then((md) => resolve({51 title: 'Interaktiver News-Artikel',52 generic: md[0].html53 }))54 .catch(reject)55 }),56 'ipa'57 ],58 '/peopleidliketoworkwith': (params) => [59 'generic',60 () => new Promise((resolve, reject) => {61 getMarkdown('peopleidliketoworkwith')62 .then((md) => resolve({63 title: 'peopleidliketoworkwith',64 generic: md[0].html65 }))66 .catch(reject)67 })68 ],69 '/blacklist': (params) => [70 'generic',71 () => new Promise((resolve, reject) => {72 resolve({73 title: 'blacklist',74 generic: 'YOLO'75 })...

Full Screen

Full Screen

JsDoc.spec.js

Source:JsDoc.spec.js Github

copy

Full Screen

...47 ],48};49describe('getMarkdown', () => {50 it('should return Markdown for all tags', () => {51 const result = getMarkdown(tags);52 expect(result).toMatchSnapshot();53 });54 it('should return Markdown for one author', () => {55 const result = getMarkdown({56 author: [tags.author[0]],57 });58 expect(result).toMatchSnapshot();59 });60 it('should return Markdown for multiple authors', () => {61 const result = getMarkdown({62 author: tags.author,63 });64 expect(result).toMatchSnapshot();65 });66});67describe('JsDoc', () => {68 it('should render Markdown', () => {69 const actual = shallow(<JsDoc {...tags} />);70 expect(actual).toMatchSnapshot();71 });72 it('should render null for empty tags', () => {73 const actual = shallow(<JsDoc />);74 expect(actual.getElement()).toBe(null);75 });...

Full Screen

Full Screen

tui.editor.js

Source:tui.editor.js Github

copy

Full Screen

...18 }19 function getHtml() {20 console.log(editor.getHTML());21 }22 function getMarkdown() {23 console.log(editor.getMarkdown());24 }25 function bindEvent() {26 document.querySelector('#getHtml').addEventListener('click', getHtml);27 document.querySelector('#getMarkdown').addEventListener('click', getMarkdown);28 }29 return {30 initEditor: initEditor,31 initViewer: initViewer,32 getHtml: getHtml,33 getMarkdown: getMarkdown,34 bindEvent: bindEvent,35 }...

Full Screen

Full Screen

PostLinks.js

Source:PostLinks.js Github

copy

Full Screen

...20 return sortPosts(posts, category).map((postsObj, i) => (21 <li key={i}>22 <Link23 to={`/${category}/${postsObj.uri}`} 24 onClick={() => getMarkdown(s3Url, `/${category}/${postsObj.uri}`)}25 >26 {postsObj.title}27 </Link>28 </li>29 ))30 }31export default connect(32 state => ({33 s3Url: state.s3Url,34 posts: state.posts35 }),36 {37 getMarkdown38 }...

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