Skip to content

Commit

Permalink
Merge c61d45e into eaf33a5
Browse files Browse the repository at this point in the history
  • Loading branch information
tyankatsu0105 committed May 16, 2020
2 parents eaf33a5 + c61d45e commit cf0c633
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -17,13 +17,14 @@
},
"main": "index.js",
"scripts": {
"test": "make test"
"test": "make test && check-dts"
},
"dependencies": {
"js-yaml": "^3.13.1"
},
"devDependencies": {
"brfs": "^2.0.2",
"check-dts": "^0.3.0",
"coveralls": "^3.0.9",
"istanbul": "^0.4.5",
"standard": "^6.0.4",
Expand Down
78 changes: 78 additions & 0 deletions test/index.errors.ts
@@ -0,0 +1,78 @@
import fm from '../'

type Attributes = {
title: string,
description: string
}

const file = `
---
title: Just hack'n
description: Nothing to see here
---
This is some text about some stuff that happened sometime ago`;

let nullBox: null;

{
/* ===================== fm ===================== */

{
// THROWS 1 arguments, but got 0.
fm()
}

{
// THROWS Argument of type 'null' is not assignable to parameter of type 'string'.
fm(null)
}

{

// THROWS 'FrontMatterResult<unknown>' is not assignable to type 'null'.
nullBox = fm(file);

// THROWS 'FrontMatterResult<Attributes>' is not assignable to type 'null'.
nullBox = fm<Attributes>(file);
}

{

let {attributes, body, bodyBegin, frontmatter} = fm<Attributes>(file);

// THROWS Property 'foo' does not exist on type 'Attributes'.
attributes.foo;

// THROWS Type 'string' is not assignable to type 'null'.
nullBox = body

// THROWS Type 'number' is not assignable to type 'null'.
nullBox = bodyBegin

// THROWS Type 'string | undefined' is not assignable to type 'null'.
nullBox = frontmatter
}
}

{
/* ===================== fm.test ===================== */

{
// THROWS 1 arguments, but got 0.
fm.test()
}

{
// THROWS Argument of type 'null' is not assignable to parameter of type 'string'.
fm.test(null)
}

{

// THROWS Type 'boolean' is not assignable to type 'null'.
nullBox = fm.test(file)
}
}

console.log(nullBox);
46 changes: 46 additions & 0 deletions test/index.types.ts
@@ -0,0 +1,46 @@
import fm from '../'

type Attributes = {
title: string,
description: string
}

const file = `
---
title: Just hack'n
description: Nothing to see here
---
This is some text about some stuff that happened sometime ago`;

{
/* ===================== fm ===================== */

{
fm(file)
}

{
const { attributes, body, bodyBegin, frontmatter } = fm<Attributes>(file);
console.log(attributes.title);
console.log(attributes.description);
console.log(body);
console.log(bodyBegin);
console.log(frontmatter);
}
}

{
/* ===================== fm.test ===================== */

{
fm.test(file)
}

{
let resultTest: boolean;

resultTest = fm.test(file);
console.log(resultTest);
}
}

0 comments on commit cf0c633

Please sign in to comment.