zaydek / duomo

CSS component for implementing layout

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Todo] Add tests cases for str-* utils

zaydek opened this issue · comments

Inside of utils there are several str-* functions. These are little helpers that take any value -- not just a string -- and convert them to strings and then do something like replace, check if the prefix is the same, or check if the suffix is the same.

It would be really helpful if we have a bunch of unit tests for these in tests/utils that test that these work. This is pretty important because if there is a problem with any of the str functions it can break a lot of things. So we want to test that the string functions work for many use cases -- non-strings, empty strings, etc.

Just a few tests per each function would be enough.

Other string utilities include str-declass and str-declass-responsive. This could very well be extracted to their own str module later.

Ignore this.

If you’re not sure where to start, I usually put an example above the function declaration, like:

// src/sass/utils/str-ends-with.scss

// Ex:
//
// str-ends-with(16, px)   -> false
// str-ends-with(16px, px) -> true
//
@function str-ends-with($src, $cmp) {
	$str-src: "" + $src;
	$str-cmp: "" + $cmp;
	@return string.slice($str-src, 1 + string.length($str-src) - string.length($str-cmp)) == $str-cmp;
}

You can use that as a guide for how to start writing a test, if it helps you.

Done