Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

escss-estest

Package Overview
Dependencies
Maintainers
0
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

escss-estest

100% coverage makes your life easier

  • 1.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
535
increased by27.99%
Maintainers
0
Weekly downloads
 
Created
Source

logo

What is ESCSS-ESTest?

ESCSS-ESTest helps you to achieve 100% coverage by taking the potential of TDD and TypeScript.

Core Concept - Water Filter

function foo() {
  {
    // unhappy path(filter to throw error)
  }

  // happy path(the result that you are expected)
}

Requirements

Vite >= 4.4.0 (if you use it)

Demo

Pure vs Impure function

import { ESTest } from 'escss-estest';

let isEnable = true

// impure function
function getSum(a, b) {
  if(!isEnable) return 0

  return a + b
}

// --------------------------------------------------
// pure function: test input by ESTest()
function getSum2(a, b) {
  {
    ESTest(a, 'number', 'mike 09102024 1')
    ESTest(b, 'number', 'mike 09102024 2')
    ESTest(isEnable, 'boolean', 'mike 09102024 3')
  }

  if(!isEnable) return 0

  return a + b
}

Error handling: async/await

import { ESTest, getData } from 'escss-estest';

async function getData() {
  const url = "https://jsonplaceholder.typicode.com/todos/99999" // undefined api
  const response = await fetch(url)
  const json = await response.json()

  {
    ESTest(json.userId, 'number', 'mike 09102024 1')
    ESTest(json.id, 'number', 'mike 09102024 2')
    ESTest(json.title, 'string', 'mike 09102024 3')
    ESTest(json.completed, 'boolean', 'mike 09102024 4')
  }

  console.log(json)
}

getData() // get error

Error handling: class

import { ESTest } from 'escss-estest';

class Animal {
  constructor(name, gender) {
    {
      ESTest(name, 'string', 'mike 09102024 1')
      ESTest(gender, 'string', 'mike 09102024 2')
    }

    this.name = name
    this.gender = gender
  }
}

new Animal('cat', 123) // get error

Usage

// Type mode
ESTest(1, "number");
ESTest(1n, "bigint");
ESTest("foo", "string");
ESTest(true, "boolean");
ESTest([], "array"); // new type
ESTest({}, "object");
ESTest(NaN, "NaN"); // new type
ESTest(null, "null"); // new type
ESTest(undefined, "undefined"); // new type
ESTest(Symbol(), "symbol");
ESTest(function () {}, "function");
ESTest(1, "object"); // error
ESTest(1, "object", "mike 09062024 001"); // The error message should provide a unique ID for troubleshooting

// Operator mode
ESTest(1, "<", 5);
ESTest(5, ">", 1);
ESTest(1, "<=", 5);
ESTest(5, ">=", 1);
ESTest(1, "!==", 2);
ESTest(1, "===", 1);
ESTest(1, "===", 100); // error
ESTest(1, "===", 100, "mike 09062024 001"); // The error message should provide a unique ID for troubleshooting

Q&A

Why not start at v1.0.0?

Because initially started at v1.0.0 and experimented quite a bit and messed around, that's why.

How to refactor legacy codebase?

Make sure you know what you are doing Before refactoring code base. When use ESCSS-ESTest make sure you have e2e、Backup branch and fellow's help, those tips will help a lot.

DISCLAIMER Author doesn't take any responsibility when you do refactoring.

Installation

  npm add escss-estest

LICENSE

see

Keywords

FAQs

Package last updated on 22 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc